StructureMap Class Chaining - Stack Overflow or other errors

Posted by Jason Young on Stack Overflow See other posts from Stack Overflow or by Jason Young
Published on 2009-09-17T18:56:07Z Indexed on 2010/03/08 0:01 UTC
Read the original article Hit count: 651

Filed under:
|

This has completely baffled me on a number of configurations. I keep reading the documentation, and I just don't get it. Here is my registration code:

ForRequestedType<SimpleWorkItemProcessor>().TheDefault.Is.OfConcreteType<SimpleWorkItemProcessor>();

ForRequestedType<WorkItemRetryProcessor>().TheDefault.Is.OfConcreteType<WorkItemRetryProcessor>()
    .CtorDependency<IWorkItemProcessor>().Is(x => x.OfConcreteType<SimpleWorkItemProcessor>())
    .WithCtorArg("busyDelay").EqualTo(TimeSpan.FromMilliseconds(20))
    .WithCtorArg("overallTimeout").EqualTo(TimeSpan.FromSeconds(60));

ForRequestedType<WorkItemQueue>().TheDefault.Is.OfConcreteType<WorkItemQueue>()
    .CtorDependency<IWorkItemProcessor>().Is(x => x.OfConcreteType<WorkItemRetryProcessor>());

As it is, it says there's no default instance for IWorkItemProcessor (which is correct). Switching the last line to this:

ForRequestedType<IWorkItemProcessor>().TheDefault.Is.OfConcreteType<WorkItemQueue>()
    .CtorDependency<IWorkItemProcessor>().Is(x => x.OfConcreteType<WorkItemRetryProcessor>());

...Makes a stack overflow exception.

How do you chain classes together that both implement an interface, and take in that same interface in their constructor?

© Stack Overflow or respective owner

Related posts about stackoverflow

Related posts about structuremap