Using Unity With Minimal Configuration

At work, we use a lot of Unity. This is great in this work, but the more you use it, the more your configuration file grows, the more problems increase during work, and the more you have to recreate your unity configuration for each test project.

So, we have a configuration section with huge unity that needs to be duplicated across several projects, and when the time comes for deployment, you will have to track the DLLs for which you forgot to add links, but you only find these at runtime. Not fun.

I assume someone has run into this problem and has a solution. Ideally, I would like to figure out how to configure Unity in such a way as to use the configuration convention and reduce run-time problems (i.e. huge configuration files). Does anyone know of a good way to implement Unity with a minimal configuration?

Edit: One thing: I should only stick to Unity. Unable to switch to Ninject, etc.

+6
c # ioc-container unity-container configuration
source share
2 answers

Unity has a configuration API, so it's pretty easy to write autoconfiguration code using reflection.

A few people reported this on the blog:

http://geekswithblogs.net/watsonjon/archive/2009/09/28/unity-convention-based-registration.aspx

http://geekswithblogs.net/brians/archive/2010/07/04/convention-based-registration-extension-for-the-microsoft-unity-ioc-container.aspx

By including this code with some framework code, you can reuse it:

http://thedersen.com/2011/02/20/convention-based-configuration-for-microsoft-unity/

This was discussed on the Unity discussion forum . The problem is that everyone wants different conventions. Look at the blog posts, writing your own seems pretty trivial.

+4
source share

In Unity 3.0, you can now customize by convention. This blog post explains this in more detail:

http://blogs.msdn.com/b/agile/archive/2013/03/12/unity-configuration-registration-by-convention.aspx

+3
source share

All Articles