对于具有以下构造的类,构造函数注入工作得很好,但不能使用属性。为了使Inject属性工作,我还需要向约定中添加什么?
public partial class Repo
{
[Inject]
public ILogger Logger{get;set;}
}绑定在NInjectWebCommon.cs中的应用
private static void RegisterServices(IKernel kernel)
{
//Dispose all resource after the requests ends
kernel.Bind(x => x.FromAssembliesMatching("*").SelectAllClasses().BindAllInterface().Configure(scope=>scope.InRequestScope()));
}发布于 2013-01-09 18:06:35
我认为存储库类以某种方式被实体框架实例化。因此,如果您没有使用ninject请求回购是,那么您需要用ninject构建现有的实例。这可以通过内核上的Inject方法来完成。
var kernel = new StandardKernel();
var repo = new Repo();
kernel.Inject(repo);https://stackoverflow.com/questions/14120931
复制相似问题