I have a solution with two relevant (to this question) projects, and a few others;
- Class library with functionality used by several other projects.
- ASP.NET MVC application.
My question is basically where I should do IoC with Ninject 2, considering...
- The class library needs some DI love, among other things in the repository classes which need web request specific session objects (think Unit of Work).
- The MVC app needs DI since with Ninject 2 you basically inherit from NinjectHttpApplication.
- Unit tests for the class library need to be aware of this to inject a different set of repositories.
- Unit tests for the web app need to be injected for the same reason.
I have painted myself into a mental corner here, because I only saw three options to begin with. DI in the class library, DI in the web app, or both, but there are problems with each:
- I can't do DI only in the class library since the MVC app needs to inherit from NinjectHttpApplication to begin with.
- I can't do DI only in the MVC app - the class library is used by other libraries, after all, and the MVC app shouldn't know too much about the internals of the library anyway.
- I guess this is the only way out I can see: Independent IoC for both projects. The class library and the MVC app each have their own IoC setup and do DI for their stuff without really caring about each other.
Does anyone have some "best practices" or guidelines on how to do something like this? I can't imagine I'm the first person to end up in this situation, and it would sure be nice to know what the "proper" way to do this is...
Thanks!