I’ve some ITask concretes types defines in my TaskRegistry:
public class TaskResigstry : Registry
{
public TaskResigstry()
{
ForRequestedType<IBootstrapperTask>().TheDefaultIsConcreteType<StartTasks>();
ForRequestedType<ITask>().TheDefaultIsConcreteType<FirstTask>();
ForRequestedType<ITask>().AddConcreteType<SecondTask>();
ForRequestedType<ITask>().AddConcreteType<ThirdTask>();
}
}
And my StartTasks
public class StartTasks : IBootstrapperTask
{
public StartTasks(ITask[] tasks)
{
foreach(var task in tasks)
{
task.Run();
}
}
}
How can i inject the ITask[] constructor parameter using StructureMap ?
Thanks.
If you want to inject an Array there’s a method for that in the fluent interface…
If you want to go down the route of an accepting an
IEnumerable<T>in your constructor as far as I can see things start to become a little more complicated. You can specify and build the constructor argument like so:-If you want all the registered types you could make a custom IBuildInterceptor that accesses all the registered types via the CreateInstanceArray method on the BuildSession but I get the feeling I might be going down the wrong road there.I’d love to be corrected that this is a lot easier :).