IoC
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)...
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...
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...