Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 带有Owin的Ninject:InRequestScope不';行不通_Entity Framework_Owin_Ninject_Ninject.web - Fatal编程技术网

Entity framework 带有Owin的Ninject:InRequestScope不';行不通

Entity framework 带有Owin的Ninject:InRequestScope不';行不通,entity-framework,owin,ninject,ninject.web,Entity Framework,Owin,Ninject,Ninject.web,我用EF6+Ninject+Owin创建了一个项目。 事实上,我意识到Ninject InRequestScope在一个Web Api请求中不起作用,我的DBContext派生类的构造函数多次激发该请求 我的web api项目的启动文件如下所示: public void Configuration(IAppBuilder app) { ConfigureOAuth(app); HttpConfiguration config = new HttpConfiguration();

我用EF6+Ninject+Owin创建了一个项目。 事实上,我意识到Ninject InRequestScope在一个Web Api请求中不起作用,我的DBContext派生类的构造函数多次激发该请求

我的web api项目的启动文件如下所示:

public void Configuration(IAppBuilder app)
{
    ConfigureOAuth(app);
    HttpConfiguration config = new HttpConfiguration();
    WebApiConfig.Register(config);
    app.UseWebApi(config);

    app.UseNinjectMiddleware(CreateKernel).UseNinjectWebApi(config);
}

private static IKernel CreateKernel()
{
    // I have my Ninject module in a separate assembly
    var kernel = new StandardKernel(new Core.Ioc.AutoBotMapper());

    GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);

    return kernel;
}
我的模块:

public class AutoBotMapper : NinjectModule
{
    private readonly ILog _logger = LogManager.GetLogger("CORE");

    public override void Load()
    {
        // Contesto is my DBContext
        Bind<Contesto>().ToSelf().InRequestScope(); 

        // Other Binds
        Bind<ITournamentServiceFactory>().ToFactory();
        Bind<ITournamentCloser>().To<TournamentCloser>();

        ...
    }
}
public class AutoBotMapper:ninject模块
{
私有只读ILog_logger=LogManager.GetLogger(“核心”);
公共覆盖无效负载()
{
//这是我的DBContext
Bind().ToSelf().InRequestScope();
//其他绑定
Bind().ToFactory();
绑定()到();
...
}
}
我没有使用引导程序“NinjectWebCommon”,因为我在网上发现了这种方法


是否存在绕过此错误的方法?

我也有同样的问题,但与ASP.NET WebForms有关。我想知道这是否是Ninject.Web.Common.WebHosts nuget软件包中引入的错误?我也有同样的问题,但与ASP.NET WebForms有关。我想知道这是否是Ninject.Web.Common.WebHosts nuget包中引入的错误?