基于以下问题:Should thoses kind of service go injected in a base class ? (versus static classes)

使用Ninject的装饰器如何完成绑定(bind)?或任何DIContainer?

public class CachedLoggedRepository : IRepository
{
   public IRepository repository { get; set; }
   void Add();
}

public class CachedRepository : IRepository
{
   public IRepository repository { get; set; }
   void Add();
}

public class Repository : IRepository
{
   void Add();
}

最佳答案

您必须使用条件绑定(bind),例如

Bind<IRepository>().To<Repository>().WhenInjectedInto<CachedRopsitory>();
Bind<IRepository>().To<CachedRepository>().WhenInjectedInto<CachedLoggedRepository>();
Bind<IRepository>().To<CachedLoggedRepository>();

关于inversion-of-control - 使用Ninject的装饰器如何完成绑定(bind)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8447037/

10-12 15:06