Reputation: 6592
I have a simple SM Registry where I am configuring all my instances of IDynamicValue. I have some contructor arguments that are non-primative types (in my case a DateTime and a Predicate Of T). Is there a way I can inject these without having to wrap them in a class with an interface (so they can be auto-wired). The following code snippet shows what I would like to accomplish:
ForRequestedType<IDynamicValue>().AddInstances(x =>
{
x.OfConcreteType<DateTimeGenerator>().WithName("DateTime")
.WithCtorArg("keyName").EqualTo("DateTime")
.WithCtorArg("startDate").EqualTo(DateTime.Now.AddMonths(-1))
.WithCtorArg("minuteIntervalDelta").EqualTo(60);
});
That example runs but fails with the exception:
StructureMap Exception Code: 202 No Default Instance defined for PluginFamily System.DateTime
Thanks, Nic
EDIT:
Freddy Rios solution worked perfect for what I needed. I am still curious if there is a method of doing this if I was auto-wiring some contructor arguments (hence couldn't use ConstructedBy())
Upvotes: 1
Views: 282
Reputation: 36035
If you are already passing all the arguments to the constructor, you could use ConstructedBy instead:
x.ConstructedBy(y => new DateTimeGenerator(
"DateTime", DateTime.Now.AddMonths(-1), 60
)
).WithName("DateTime");
Upvotes: 1