This helpful article from David Haydn (EDIT: scam link removed, it could have been this article) shows how you can use the InjectionConstructor
class to help y
Another approach, thanks to a suggestion from @DarkSquirrel42, is to use an InjectionFactory
. The downside is that the code still needs updating every time a new constructor parameter is added to something in the chain. The advantages are much easier to understand code, and only a single registration into the container.
Func createChain = container =>
new LoggingProductRepository(
new CachingProductRepository(
container.Resolve(),
container.Resolve()),
container.Resolve());
c.RegisterType(new InjectionFactory(createChain));
Assert.IsInstanceOf(c.Resolve());