views:

677

answers:

1

I have some providers, say -

<Providers>
    <Provider Type="Providers.IM"  Name="Im"/>
    <Provider Type="Providers.Web" Name="Web"/>
    ...
</Provider>

Each of these providers can give me a session :

<Sessions>
    <Session Name="GoogleIM" Provider="Im"  URL="..." />
    <Session Name="YahooIM"  Provider="Im"  URL="..." />
    <Session Name="YahooWeb" Provider="Web" URL="..." />
    ...
</Session>

Currently, I instantiate "named" sessions by looking at the provider, instantiating the type, and injecting the URL (manually).

I could use a session factory, which would probably have to understand the url and return a proper session.

Is there a way to handle this more elegantly/simply with ninject/autofac?

+1  A: 

I may not understand your setup correctly but I believe you could handle this type of operation with Ninject pretty easily. You would want to create a base interface and have all your objects implement that. Your Ninject bindings will use the Context to determine which class to load in place of your interface type. I wrote a brief tutorial using Ninject's contextual binding available here : http://frickinsweet.com/ryanlanciaux.com/post/Real-Ultimate-Power--Dependency-Injection-with-Ninject.aspx

Ryan Lanciaux