Watson Jon

Code and ramblings from Watson
posts - 15, comments - 7, trackbacks - 0

My Links

News

Twitter












Archives

Post Categories

User Groups

IoC

Injecting an array of objects with Unity
If you only have one implementation of a registered interface then it is pretty straight forward, but what do you do if you have multiple implementations of an interface? Now you have to get a little more explicit when registering items in your container. Let’s go through a simple example. Say you have a class, OrderProcessor, that takes one implementation of IMessageWriter: public class OrderProcessor { private readonly IMessageWriter _messageWriter; public OrderProcessor(IMessageWriter messageWriter)...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Monday, October 19, 2009 10:56 PM | Feedback (1) | Filed Under [ IoC ]

Unity Convention Based Registration
Maybe it is just me, but I’m not a big fan of huge amounts of XML configuration. I can get by with a few name-value pairs in an app.config or a web.config but much more makes me nervous that I’m going to mistype something and not know about it until run time. I’ve been using Unity and it has the ability to load up its configuration from the app.config or web.config. Here’s a sample: Yeah…..what else ya got? It offers a “fluent” API for programmatic registration. Sweet! Now I just have to convert...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Monday, September 28, 2009 9:35 PM | Feedback (1) | Filed Under [ IoC ]

Motivations for Dependency Injection
I’m working on a presentation for the Baton Rouge .Net User Group in October on DI so I thought I’d go over some of the reasons to move to DI. Here’s my short list: Better design through loose coupling That’s about it. There are other reasons that I consider side effects of good design: Testability – easier to test components in isolation since their dependencies can be mocked Flexibility – easier to use alternative implementations since you only need to change the registered components Those are...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Monday, September 21, 2009 9:50 PM | Feedback (0) | Filed Under [ IoC ]

Powered by: