Autofac Lifetimes and the Default Provider within a Matching Lifetime Scope

后端 未结 2 1831
失恋的感觉
失恋的感觉 2021-02-09 15:38

I have an ASP.NET MVC web application using Autofac for dependency injection. Occasionally, this web application will start a thread to do some work separate from the request t

2条回答
  •  广开言路
    2021-02-09 15:55

    Register the web Foo as normal, but don't register the other Foo. When creating the lifetime scope for the async task, use the overload of BeginLifetimeScope() that takes an action on ContainerBuilder. Register the background Foo in this action (b => b.Register()) and this should override the web one. (Small keyboard here sorry :))

提交回复
热议问题