Wednesday, April 30, 2014

Did you know that when StructureMap maps a class to an interface that when the class gets instantiated that the constructor with the most parameters will get called?

What's that? You say you've never seen parameters passed in in the mappings and thus this doesn't make sense? I've never seen this either, but you may specify at the constructor in these scenarios other interfaces which are also hydrated (given dance partners in the form of classes) by StructureMap and StructureMap should "fill in the gaps" so to speak. When undertaking this sort of trickery, you will be golden provided you do not create a circular reference.

Bonus: There is a NuGet package, and it might be StructureMap.MVC4 (not sure), which allows for the interfaces to be handed in and hydrated at the constructor signatures of MVC controllers!

No comments:

Post a Comment