Register Multiple Components for Single Interface Using Castle Windsor

久未见 提交于 2020-01-01 18:05:30

问题


I am trying to register multiple NHibernate ISessions (multiple databases) by using the code below. 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.

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"));

回答1:


This was fixed a couple of months ago. Please get a recent build from the buildserver.



来源:https://stackoverflow.com/questions/1784653/register-multiple-components-for-single-interface-using-castle-windsor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!