2012-03-07 65 views
0

我对城堡和Ninject很新颖。怎么过,我有其中一个接口初始化为工厂方法,这样ninject中的asfactory实现与城堡形成鲜明对比

public class LazySessionContext 
{ 
    private readonly ISessionFactoryImplementor factory; 
    private const string CurrentSessionContextKey = "NHibernateCurrentSession"; 

    public LazySessionContext(ISessionFactoryImplementor factory) 
    { 
     this.factory = factory; 
    } 
} 

现在注射ISessionFactoryImplementor作为工厂方法时,我们已经做了这样的

public void Install(IWindsorContainer container, IConfigurationStore store) 
    { 


     container.Register(Component.For<ISessionFactoryProvider>().AsFactory()); 

     container.Register(Component.For<IEnumerable<ISessionFactory>>() 
            .UsingFactoryMethod(k => k.ResolveAll<ISessionFactory>())); 

    } 

一份声明中有人可以请注明如何实现在ninject中是一样的吗?所以ISessionFactoryProvider作为ninject中的工厂方法提供并初始化?

回答

1
kernel.Bind<ISessionFactoryProvider>().ToFactory(); 

是等效的。到这个配置。你必须使用Ninject.Extensions.Factory。 IEnumerable配置默认存在。

+0

感谢您告知扩展程序不知道ninject的扩展:) – Joy 2012-03-09 04:25:57