示波器在温莎城堡类型的工厂中丢失?

Scope gets lost in Castle Windsor typed factory?

我在带有 TypedFactoryFacility 的容器中有以下 Windsor 组件注册代码:

Component
    .For<IMyItemFactory>()
    .AsFactory(f => f.SelectedWith(new MyComponentSelector()))
    .LifestylePerWcfOperation(),

Classes
    .FromAssembly(Assembly.GetExecutingAssembly())
    .BasedOn<IMyItem>()
    .LifestylePerWcfOperation()
    .Configure(c => c.Named(c.Implementation.Name)),

致力于创建 IMyItemFactory 的自动实现。在执行 IMyItemFactory 工厂方法程序期间失败并出现异常

Castle.MicroKernel.ComponentResolutionException: Could not obtain scope for component SpecificItem. This is most likely either a bug in custom IScopeAccessor or you're trying to access scoped component outside of the scope (like a per-web-request component outside of web request etc)
   at Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.GetScope(CreationContext context)
   at Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy)
   at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
   at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
   at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
   at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy)
   at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(String key, Type service, IDictionary arguments, IReleasePolicy policy)
   at Castle.Facilities.TypedFactory.TypedFactoryComponentResolver.Resolve(IKernelInternal kernel, IReleasePolicy scope)
   at Castle.Facilities.TypedFactory.Internal.TypedFactoryInterceptor.Resolve(IInvocation invocation)
   at Castle.Facilities.TypedFactory.Internal.TypedFactoryInterceptor.Intercept(IInvocation invocation)
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Castle.Proxies.IMyItemFactoryProxy.GetMyItem(String myItemType)

应用程序中的几乎每个组件都有 WcfOperation 作用域,这令人困惑,所以我不明白这是怎么发生的。我什至尝试记录每个已注册的类型及其范围,以断言 IMyItem 类 具有 WcfOperation 范围——它们具有。

你知道如何调试吗?

编辑:我正在使用 WcfOperation 范围从成功构建的对象调用工厂,该范围可以毫无问题地调用另一个 WcfOperation 范围的服务:

public SomeDataProvider(IElasticsearchClient elasticClient, IMyItemFactory factory)
{
    _elasticClient = elasticClient;

    _factory = factory;
}

async Task SomeMethod()
{
    var someString = await _elasticClient.SomeMethod(); // ok

    var myItem = _factory.GetMyItem(someString); // exception from above

    // ...
}

如评论中所述,OperationContext.Currentnull,因此从技术上讲,温莎做了正确的事情 - 提醒您注意这一事实。