Architecture : Implementing IOC

I’m guessing this is obvious to most of you, but it would be good to get some comments. Most IOC examples I have seen tend to be kind of trivial, it’s easy to expose the required dependent as a property or a constructor argument. I’m wondering about the implementation in cases where: The object needs access to a factory for the objects as it is long lived and requires to create them on an ongoing basis, objects that require several dependents and deep trees where each level has options on implementation.

It’s the sort of problem you can approach using a locator easily enough e.g. Unity.

I’m not too keen on that approach because I prefer my dependencies and configuration to be spelled out.

Given that we ca be dealing with a tree means that constructing from the lowest level up isn’t too clear either, especially if there are factories involved.

My approach at the moment is to craft a structure with named methods for all the dependents in a tree. If there is a requirement to build objects on the fly, then the property for that situation is of type Func<…IOUT> where there are the required number of parameters. There is a top level object with properties for all the trees.

For me, this seems to provide the minimum of coding, yields ease of testing, makes all dependencies explicit and allows specific implementations in a deployment easy to find.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply