与异步\ await一起使用时Castle Windsor LifestylePerWcfOperation

时间:2018-08-08 16:47:16

标签: c# async-await castle-windsor

我正在使用温莎城堡作为我的DI容器构建WCF服务。 我还将DbContext(称为MyAppEntities)配置为LifestylePerWcfOperation。 当我尝试添加

时问题开始
[OperationContract]
Task<string> ExecuteAsync(string request);

我是这样实现的:

public async Task<string> ExecuteAsync(string request)
{
    return await Task.Factory.StartNew(() => [some work is done 
    here...]);
}

发生的事情是该任务中的工作试图解析其中一个存储库并获取下一个异常:

  

无法获取组件MyAppEntities的范围。   这很可能是自定义IScopeAccessor中的错误,或者您试图访问范围之外的范围化组件(例如,Web请求之外的每个Web请求组件等)   System.ServiceModel.FaultException`1 [System.ServiceModel.ExceptionDetail]:无法获取组件MyAppEntities的范围。   这很可能是自定义IScopeAccessor中的错误,或者您正试图访问范围之外的作用域组件(例如,Web请求之外的每个Web请求组件等)(故障详细信息等于ExceptionDetail,可能是由IncludeExceptionDetailInFaults = true,其值为:   Castle.MicroKernel.ComponentResolutionException:无法获取组件MyAppEntities的范围。这很可能是自定义IScopeAccessor中的错误,或者您试图访问范围之外的范围化组件(例如,Web请求之外的每个Web请求组件等)      在Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.GetScope(CreationContext上下文)      在Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.Resolve中(CreationContext上下文,IReleasePolicy releasePolicy)      在Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext上下文,布尔RequiresDecommission,布尔InstanceRequired,负担&负担)      在Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext上下文,Boolean instanceRequired)      在Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext上下文)      在Castle.MicroKernel.Resolvers.DefaultDependencyResolv ...)。

0 个答案:

没有答案