Pregunta

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());
¿Fue útil?

Solución

There's nothing wrong with that pattern; it's actually quite common.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top