简体   繁体   中英

One DI Container for multiple ASP.Net applications

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM