How can I tell SM to not use the greediest constructor?

53 views
Skip to first unread message

Jeff Schumacher

unread,
Sep 2, 2009, 3:32:31 PM9/2/09
to structuremap-users
Assuming that I remember correctly, and it seems so from experience,
StructureMap will always use the greediest constructor when
instantiating a class.

How can we tell SM to not use the greediest constructor?

Example, a class has 2 constructors, one without parameters, and the
other with a single parameter. I want SM to give me an instance of the
class using the parameterless constructor.

Thanks!

Jeff

gsogol

unread,
Sep 2, 2009, 3:35:31 PM9/2/09
to structuremap-users
I had the same issue nad used ConstructedBy() as in:

.Is(o => o.OfConcreteType<SOME_CLASS>()
.CtorDependency<IInterface1>()
.Is(a => a.ConstructedBy(() => new SOME_CLASS(

Jeremy D. Miller

unread,
Sep 2, 2009, 3:35:50 PM9/2/09
to structure...@googlegroups.com
Look here and see if this helps:  http://structuremap.sourceforge.net/ConstructorAndSetterInjection.htm#section2

 
Jeremy D. Miller
The Shade Tree Developer
jeremy...@yahoo.com



From: Jeff Schumacher <je...@codingreflection.com>
To: structuremap-users <structure...@googlegroups.com>
Sent: Wednesday, September 2, 2009 2:32:31 PM
Subject: [sm-users] How can I tell SM to not use the greediest constructor?
Reply all
Reply to author
Forward
0 new messages