The adventure of writing meaningful code.
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.
| Print article | This entry was posted by dan on February 11, 2010 at 9:37 am, and is filed under Best practice, C#, Inversion of Control, Patterns, Tips. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 6 months ago
I would like to see two stacks of code w/wo unity support. One can tell significant amount of improvement just by counting how many lines of code are reduced.
Also, the link to unity is broken.
about 6 months ago
@Yudi
Ahhh, thanks, fixed the link.
Good point, I will make a new post showing the improvements when using an inversion of control container. Then I will update this post with a link to that post.