There's nothing wrong with that pattern; it's actually quite common.
Question
In a container, I have an FooFactory registered and another component which needs an Foo.
class FooFactory {
FooFactory(Bar bar) { ... }
Foo CreateFoo() { ... }
}
class FooConsumer {
FooConsumer(Foo foo) { ... }
}
builder.RegisterType<FooProvider>();
builder.RegisterType<FooConsumer>();
Is there a better way for Autofac to wire up the call to CreateFoo than calling c.Resolve during registrations, or does this look pretty much the right way?
builder.Register(c => c.Resolve<FooFactory>().CreateFoo());
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow