C# DryIoc与ASP.NET WebApi和HostingEnvironment.QueueBackgroundWorkItem()的正确用法是什么?
我正在将DryIoc引入现有的ASP.NET WebAPI项目中。我使用以下容器设置,然后使用寄存器(省略): 这一切都按预期进行 但是,我们还使用C# DryIoc与ASP.NET WebApi和HostingEnvironment.QueueBackgroundWorkItem()的正确用法是什么?,c#,asp.net,asp.net-web-api,dryioc,C#,Asp.net,Asp.net Web Api,Dryioc,我正在将DryIoc引入现有的ASP.NET WebAPI项目中。我使用以下容器设置,然后使用寄存器(省略): 这一切都按预期进行 但是,我们还使用HostingEnvironment.QueueBackgroundWorkItem()在某些WebApi调用结束时对后台工作进行排队。这导致该后台工作项报告以下错误: 2019-08-13T20:53:36.5792777Z ERROR LAPTOP XXX.Models.SomeModel [/] (): Error in Report Proc
HostingEnvironment.QueueBackgroundWorkItem()
在某些WebApi调用结束时对后台工作进行排队。这导致该后台工作项报告以下错误:
2019-08-13T20:53:36.5792777Z ERROR LAPTOP XXX.Models.SomeModel [/] (): Error in Report Processing DryIoc.ContainerException: Container is disposed and should not be used: "Container with ambient ScopeContext DryIoc.AsyncExecutionFlowScopeContext without Scope
with Rules with Made={FactoryMethod=ConstructorWithResolvableArguments} has been DISPOSED!
You may include Dispose stack-trace into the message via:
container.With(rules => rules.WithCaptureContainerDisposeStackTrace())"
at DryIoc.Throw.It(Int32 error, Object arg0, Object arg1, Object arg2, Object arg3)
at DryIoc.Container.ThrowIfContainerDisposed()
at DryIoc.Container.DryIoc.IResolver.Resolve(Type serviceType, Object serviceKey, IfUnresolved ifUnresolved, Type requiredServiceType, Request preResolveParent, Object[] args)
at (Closure`2 )
at FastExpressionCompiler.LightExpression.ExpressionCompiler.CurryClosureFuncs.<>c__DisplayClass2_0`2.<Curry>b__0()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at XXX.Models.SomeModel.GetReporting(Int32 pid, Int32 oid, Int32 uid, Int32 peid) in C:\src\XXX\XXX\Models\SomeModel.cs:line 2277
并且后台任务是成功的,因为存在依赖项
然而,我不确定这是否是正确的做法,以及以后是否会有问题。DryIoc与ASP.NET WebApi和HostingEnvironment.QueueBackgroundWorkItem()的正确用法是什么
2019-08-13T20:53:36.5792777Z ERROR LAPTOP XXX.Models.SomeModel [/] (): Error in Report Processing DryIoc.ContainerException: Container is disposed and should not be used: "Container with ambient ScopeContext DryIoc.AsyncExecutionFlowScopeContext without Scope
with Rules with Made={FactoryMethod=ConstructorWithResolvableArguments} has been DISPOSED!
You may include Dispose stack-trace into the message via:
container.With(rules => rules.WithCaptureContainerDisposeStackTrace())"
at DryIoc.Throw.It(Int32 error, Object arg0, Object arg1, Object arg2, Object arg3)
at DryIoc.Container.ThrowIfContainerDisposed()
at DryIoc.Container.DryIoc.IResolver.Resolve(Type serviceType, Object serviceKey, IfUnresolved ifUnresolved, Type requiredServiceType, Request preResolveParent, Object[] args)
at (Closure`2 )
at FastExpressionCompiler.LightExpression.ExpressionCompiler.CurryClosureFuncs.<>c__DisplayClass2_0`2.<Curry>b__0()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at XXX.Models.SomeModel.GetReporting(Int32 pid, Int32 oid, Int32 uid, Int32 peid) in C:\src\XXX\XXX\Models\SomeModel.cs:line 2277
_ = diVariable.Value;