Suppose I have an ASP.NET MVC web application that consists of many assemblies. Here is a very simple example:
- Myapp.web
- MyApp.Services
- contains interfaces and implementations of domain services, for example. IOrderProcessor, DefaultOrderProcessor
- MyApp.DAL
- contains interfaces and repository implementations, for example. IOrderRepository, SqlOrderRepository
The web application will initialize the IoC container at startup (for example, register controllers, etc.). I’m not sure whose responsibility for registering domain services and repositories should be.
Now I have created a static class in each assembly, each of which contains a method responsible for registering the types contained in the assembly. For instance. To build DAL:
namespace MyApp.DAL
{
public static class AssemblyInitialization
{
public static void RegisterTypes(IUnityContainer container)
{
var lm = new TransientLifestyleManager();
container.RegisterType<IOrderRepository, SqlOrderRepository>(lm);
...
}
}
}
- ( unit-test , , , ).
, . , IoC (Unity , ). , - ( -).
, , :