views:

414

answers:

4

After attending a recent Alt.NET group on IoC I got to thinking about the tools available and how they might work. StructureMap in particular uses both attributes and bootstrapper concepts to map requests for IThing to ConcreteThing. Attributes automatically throw up flags for me that either reflection or IL injection is going on. Does anyone know exactly how this works (for StructureMap or other IoC tools) and what the associated overhead might be either at run-time or compile-time?

A: 

I can't say much for other IoC toolkits but I use Spring.Net and have found that there is a one off initial performance penalty at startup. Once the container has been configured the application runs unaffected.

tgeros
Thanks...I actually hadn't heard of Spring.Net, do you like it?
JC Grubbs
+1  A: 

They major problem is that code becomes hard to understand. It might become pure magical if one overuse IoC. Another problem is performance. In most cases performance lost is not noticeable. But when you start creating most of your objects via IoC container, it can suddenly drop below ocean level.

aku
How big can the performance loss be? What did you measure?
Rookian
+1  A: 

I use Windsor from the CastleProject and have found it immensely useful in reducing dependencies. I haven't noticed a performance issue yet but one thing I do find is that the configuration can get a bit cumbersome. To help in this regard I'm starting to look at Binsor, which is a DSL for Windsor written in boo.

Another thing to be aware of is that when navigating code you wont be able to go to the code that will be executing at runtime.

Darren
A: 

I built a very lightweight and basic IOC, here:

http://blogs.microsoft.co.il/blogs/shay/archive/2008/09/30/building-custom-object-mapper.aspx

It's not an alternative to the libraries You mentioned but if all that You need is to resolve a type by giving its interface it might be a perfect solution.

I don't handle instantiation types (singleton, transient, thread, pool...), all object will be instantiated as singletons, you call it like:

IRepository _repository = ObjectFactory.BuildFactory();

Shay