English 中文(简体)
不从事子类工作的注射
原标题:Ninject injection not working on subclasses

我试图增加第三层的约束力,但我找不到这样做的适当途径。 I m使用Ninject 3.0,我有以下假设:

public class ClassBase 
{
  [Inject]
  public IRepository RepositoryInstance { get; set; }
}

public class ClassA : ClassBase {} 
public class ClassB : ClassA {}

public class RepA : IRepository {}
public class RepB : IRepository {}

我如何将再婚与班级联系起来 能够有这种存放处,而B类则应当受B类的管制?

Thanks

问题回答

You might use WhenInjectedInto() ninject IBindingWhenSyntax<T> interface.

因此,具有约束力的法典将研究类似的东西。

kernel.Bind<IRepository>().To<RepA>().WhenInjectedInto<ClassA>();
kernel.Bind<IRepository>().To<RepB>().WhenInjectedInto<ClassB>();

As far a I remember, the Inject attribute is deprecated and should not be used. I would use a constructor to inject it or in specific class I wolud use this kind of method IKernel kernel = new StandardKernel(); var samurai = kernel.Get();

如下文所示:https://github.com/ninject/ninject/wiki/Dependency-Injection-With-Ninject





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签