简体   繁体   English

使用Castle Windsor为单个接口注册多个组件

[英]Register Multiple Components for Single Interface Using Castle Windsor

I am trying to register multiple NHibernate ISessions (multiple databases) by using the code below. 我正在尝试使用下面的代码注册多个NHibernate ISessions(多个数据库)。 I am getting "There is a component already registered for the given key Castle.MicroKernel.Registration.GenericFactory`1[[NHibernate.ISession, NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4]]" as the error message when the container is trying to be built. 我收到错误消息“已经为给定的Castle.MicroKernel.Registration.GenericFactory`1 [[NHibernate.ISession,NHibernate,Version = 2.1.0.4000,Culture = neutral,PublicKeyToken = aa95f207798dfdb4]]注册了组件”作为错误尝试构建容器时出现此消息。

container.Kernel.Register(
    Component.For<ISession>().LifeStyle.Transient
        .UsingFactoryMethod(() => sessionFactoryOne.OpenSession()
        ).Named("ISession+sessionOne"));

container.Kernel.Register(
    Component.For<ISession>().LifeStyle.Transient
        .UsingFactoryMethod(() => sessionFactoryTwo.OpenSession())
         .Named("ISession+sessionTwo"));

This was fixed a couple of months ago . 这是几个月前解决的 Please get a recent build from the buildserver . 请从buildserver获取最新版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Castle Windsor fluent API注册实现多个接口的组件 - Using Castle Windsor fluent API to register components implementing multiple interfaces 在Castle Windsor中向多个服务注册多个组件 - Register multiple components with multiple services in Castle Windsor 在Castle Windsor中注册同一接口的多个实现 - Register multiple implementations of same interface in Castle Windsor 温莎城堡注册多种类型的基本接口? - Castle Windsor register multiple types of a base Interface? 在 Castle Windsor 中注册泛型接口的多个实现 - Register multiple implementations of generic interface in Castle Windsor Castle Windsor注册了一个界面 - Castle Windsor register an interface 当还有专门的服务类型时,使用 Castle Windsor 的流畅接口在装饰器链中注册组件? - Using Castle Windsor's fluent interface to register components in a decorator chain, when there are also specialised service-types? Castle Windsor:如何在实现特定接口时注册多种类型? - Castle Windsor: how to register multiple types as implementing a specific interface? 如何使用Castle Windsor的基本接口注册服务工厂模式 - How to register Service Factory Pattern using base interface with Castle Windsor 温莎城堡注册多个实例 - Castle Windsor register multiple instances
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM