Using Unity in framework like code.

Jan 27, 2014 at 9:45 PM
I am starting work on a new framework type of code, i.e. a set of class libraries designed to be incorporated into other code. I foresee that the use of a DI container for my work will be vary useful and make the testing of the framework much easier.

However, as I am fairly new to the DI/IoC world as well as Unity, I do not see how to accomplish this with out making the use of the DI container of My choice (i,e, Unity) become a burden on the consumer of my framework.

So, I guess that my question is how/where would I create the container for my use, such that I am not making a requirement that the consuming code know anything about my choice of DI container (or even that I am using one)?
Jan 28, 2014 at 1:19 PM
Will consumers of your framework know that you support dependency injection and have the option to user their own container? If that is the case then you can use the
Common Service Locator library to abstract away the specific container. Enterprise Library 5 lets you do this and ASP.NET MVC takes a similar approach.

If you just want to internally use Unity without any consumers knowing about it you can reference Unity in your framework and perform all configuration using programmatic configuration. The only external dependency would be that the appropriate (Unity) assemblies would need to be deployed. If you didn't want to deploy the Unity assemblies you could merge the assemblies with your assemblies (using ILMerge for example. Another approach would be to include assemblies as embedded resources in your project and subscribe to the AssemblyResolve event.

Randy Levy
Enterprise Library support engineer
Support How-to