views:

89

answers:

1

Hi All,

I am trying to design a Infrastructure libraries for my company. Libraries will have typical components like logging, exception handling, email etc. These componants will be used by all the ASP.Net applications hosted on our environment (so hosting environment is my control).

My first step in design is that I would not like the ASP.nEt apps to have direct reference to the library componants. So i am thinking to Injecting these dependecies at runtime. I have evaluated quite a few DI containers (unity, spring.net etc)

But what i dont have to do is to force all the ASP.Net applications to use this DI container. They will be getting a interface Dll for all the library componants and some kind factory dll which will give them the concrete instance of the componant.

My question is whats the best way to design this Factory dll so that only one dll can service all the ASP.Net applications? Can i use one DI container to service all the ASP.Net applications?

+1  A: 

Well, you could simply define a container interface like this:

public interface IContainer
{
    T Resolve<T>();
}

(obviously you can add more methods if you need to). You can then create concrete implementation of this IContainer interface based on your DI Container of choice.

Such concrete implementations could encapsulate all the configuration that your application needs in terms of registered components.

Your ASP.NET applications would simply consume the IContainer interface and call the Resolve method to get instances of the necessary components.

Mark Seemann
Thanks for answer Mark... I think i have not put my question in a right way. My problem is not that i have multiple DI container to decide from. I will have only one DI container. My mail problem is how will that DI container be used by multiple ASP.Net application. More like a Single DI Container (a Single wrapper class over DI container)... i hope this make sense or if not is it OK to have each ASP.Net application create an instace of the wrapper class and the DI container takes care of the creation of the library components..
rauts
@rauts: Then why don't you just create an instance of your selected container directly in global.asax (or a similar place)? That's the whole idea...
Mark Seemann
@rauts: Take a look at this SO answer that explains what I meant by my previous comment: http://stackoverflow.com/questions/1410719/design-where-should-objects-be-registered-when-using-windsor/1410738#1410738
Mark Seemann
Thanks a lot. I think I am much more clear now...
rauts