IoCs .NET

I also use Autofac, but I have to use Windsor at work. There isn't really much difference between the two, Windsor probably requires less wiring and is easier to learn. Both have decent documentation though.
 
I'm yet to need one, tbh. Does anyone find any genuine advantages to using them? I am asking for honesty here, not just the usual "It means I can just pull my dependencies" etc. :)

We experimented with them for a while, and found they were just a PITA, and only replaced the usual dependency problems, with different problems.
 
Well we use windsor for class lifecycle management as well, when you set it up you can say how the class should be handled ie as a singleton. Then wherever you are in code when you ask your ioc for this object and it's guaranteed to be the singleton version. It works well with splitting up large mvc sites where you might use a shared query or command repository over and over.
 
I'm yet to need one, tbh. Does anyone find any genuine advantages to using them? I am asking for honesty here, not just the usual "It means I can just pull my dependencies" etc. :)

We experimented with them for a while, and found they were just a PITA, and only replaced the usual dependency problems, with different problems.

What sort of issues did you run into?
I would hate to develop without using some sort of IoC container these days.
If you're using dependency injection it would surely be an utter pain to new up objects if you don't have a container to manage things for you?
 
To be honest, I'd pick which one to use based on whether or not you like the API or not. Unless you're doing "advanced" things they are mostly much of a muchness, although they all have their own opinions and issues with how to handle certain things.

I've used TinyIoC, Autofac, StructureMap and Unity on various projects.
 
What sort of issues did you run into?
I would hate to develop without using some sort of IoC container these days.
If you're using dependency injection it would surely be an utter pain to new up objects if you don't have a container to manage things for you?

Nothing major, just the typical wrong implementation getting used for 'x' interface under 'y' context. I.e. we have multiple implementers of a given interface, and IoC not knowing which to use, or worse using the wrong one. :)

Overall it just didn't make things any easier. Didn't make them significantly any more difficult I must add though.
 
Nothing major, just the typical wrong implementation getting used for 'x' interface under 'y' context. I.e. we have multiple implementers of a given interface, and IoC not knowing which to use, or worse using the wrong one. :)

Overall it just didn't make things any easier. Didn't make them significantly any more difficult I must add though.

You should specify a default interface, then override if you need to.

Also, doesn't have DI/IoC make testing easier?
 
Nothing major, just the typical wrong implementation getting used for 'x' interface under 'y' context. I.e. we have multiple implementers of a given interface, and IoC not knowing which to use, or worse using the wrong one. :)

Overall it just didn't make things any easier. Didn't make them significantly any more difficult I must add though.

I can certainly see that in the case where you have multiple implementers of a single interface it can be a pain.
Generally that's the sort of stuff I'd shy away from using an IoC container for anyway.

Where I find it really pays dividends is in the general infrastructure type stuff.
My day to day work is using WPF, where you might have a viewmodel that is bound to a view.
That viewmodel will likely have several dependencies of things like UI & infrastructure services, possibly other viewmodels.
Those things in turn may have other dependencies themselves.

If you need to introduce another dependency to a viewmodel, you just put it in the constructor and let the container handle things for you if you have one.
Otherwise you'd need to change things wherever you create that class. Even if you have a factory to sort it all out and ensure it's all done in one place, you still need to potentially deal with chains of dependencies that are being passed in.

Obviously it's not great practice to have everything with dependencies to everything else, but it's certainly the case where most things aren't quite as simple as just adding in an extra object to the constructor.

Additionally, things like the auto mocking framework I linked above provide lots of benefits.
When creating tests you simply resolve the object through the auto mocker and it creates any dependencies as proxy objects.
Any of them you need to mock a particular method call, you can just get that proxy and mock out the method.
 
Yeah, we use automock stuff, that's a little different though because it is a clear boundary as it is only ever one level deep.

I can certainly see the plus side to IoC Containers, and the merit they provide - but I'm still undecided if that actually is a pro or a con. We've got a rats nest of a dependency graph as it is. Having an IoC container will make it easier for this graph to get even more convoluted. This is the double edged sword of IoC Containers - they take away the managing of that graph, but they also make it very easy to have a hideous graph.
 
Last edited:
Autofac. It doesn't have a GodFactory (which are stupid and defeat the point). It is a pure, opinionated and elegant IoC container. Mapping out your dependency graphs with it is a thing of beauty.
 
Back
Top Bottom