I am facing some architectural problems in a project in which I participate. The project is an ASP.NET MVC 2 application based on DI and especially on embedding a constructor with Unity. The application is divided into several modules (each module is a set of assemblies), which provides services to other modules. These services register with Unity when the application starts. Nothing special so far. Let's say I have this (each module is an assembly for simplification):
ModuleA, ModuleB.
ModuleA provides the IServiceA service with the following methods:
IServiceA (Operation1 - Operation2 - Operation3)
ServiceB from ModuleB needs IServiceA from ModuleA and gets it by injection of the constructor (with a specific implementation). Then he uses it.
The problem is that ModuleA is deactivated (we check the database if the module is activated for the current user when the application starts), therefore serviceA is not registered in Unity.
Then we have an exception at runtime because unity cannot find the registration for IServiceA and ServiceB cannot be built. This is normal.
I would like to know that there is a set of templates or best practice to solve this problem. My first, though, was to get rid of the constructor injection for ServiceB. But then I have to use a solid link to ServiceA, and I don't like it, or use ServiceLocator, which is even worse. I do not want to check ModuleB if ServiceA is available or not, because there will be many other services that I would check, and must deal with code that is purely infrastructure. I would like ServiceB to run the same code if serviceA is available or not (I don't know if this is possible). I looked at the Gateway pattern, but I don’t know if this can help me.
Any help would be appreciated.
Thank,