I have 4 projects:
Core (IServer):
- System
- System.Core
DependencyResolver:
- Core
- StructureMap
Infrastructure (Service):
- Core
- External dependency
Console:
- Core
- DependencyResolver
Requierements:
I am trying to use StructureMap only in the DependencyResolver. Furthermore the Console application should not know anything about Infrastucture.
When I do not want to reference StructureMap on my Console Application I have to build a ServiceLocator.
In the DependencyResolver I have a Bootstrapper that is responsible for calling StructureMap registry stuff (Register)
In my Console application I want to get an instance. For this I need to reference StructureMap. Another way would be to write a little wrapper around StructureMaps resolving methods.
Is there any other better way of decoupling the console from StructureMap?
While I see a reason for separating IoC register,resolve,release from the implementation of the application, I don't see any reason why the IoC container shouldn't be in the console application (the composition root) and the application implemention in another assembly instead.
That way the console application is very easy:
With SM it look about like this:
For things you can't create at startup you create a factory interface in your application assembly:
and implement this interface in the console application by injecting the container and use it to resolve the instance. I guess the SM implementation looks like this:
Other IoC container even have the functionallity to implement these interface factories automatically.