configure Castle Windosor and generic

2019-05-11 10:58发布

问题:

this is my code in Global.asax

 WindsorContainer container = new WindsorContainer();
container.Register(Component.For(typeof(IRepository<>))
                                       .ImplementedBy(typeof(NHRepository<>))
                                       .LifeStyle.Transient)

I've tried to translate it in a xml config file with this but didn't work

<component id="NHRepository"
           service="NCommon.Data.IRepository'1, NCommon"
           type="NCommon.Data.NHibernate.NHRepository'1, NCommon.NHibernate"
           lifestyle="transient">
</component>

How can I convert this code in a config file as Windsor.config ?

Tanks Mirko

回答1:

You need to use backticks, not apostrophes

<component id="NHRepository"
           service="NCommon.Data.IRepository`1, NCommon"
           type="NCommon.Data.NHibernate.NHRepository`1, NCommon.NHibernate"
           lifestyle="transient">
</component>