Feb 11 2010

Unitiy IOC

Basically, with Unity, I ended up writing something like this (simplified version) :

IUnityContainer container = new UnityContainer();

container.RegisterType<IRiskRepository, RiskRepository>();

string conn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

container.Configure<InjectedMembers>().ConfigureInjectionFor<RiskRepository>(new InjectionConstructor(conn));

UnityControllerFactory factory = new UnityControllerFactory(container);

ControllerBuilder.Current.SetControllerFactory(factory);

Unity turned out to work very well. I was able to save a lot of lines of code and it is greatly improving the testability of the dynamic modules I am using on the mock project architecture. Also, it was easy to set up. Its a good alternative to the other more popular IOC.

  • Share/Bookmark

Feb 4 2010

Inversion of Control

If you are building an application that has a lot of modules and those modules can be plugged in dynamically then you will probably want to use inversion of control (IoC).

What can inversion of control do for you?

  • help you deal with the configuration of all the modules
  • a one “single point change” so you wont have to hunt down every other place where things could go wrong
  • help with transparency as you just have to use a module and not worry how it is implemented
  • provide a nice way to have strong contracts (due to interfaces)
  • finally, the application can change it’s own behavior when it believes it is necessary at runtime

If you want to learn more I would recommend reading the the famous article written by Martin Fowler.

  • Share/Bookmark