문제

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());
도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top