Owin上下文中使用每个请求的单个实例 [英] Owin Context to use a single instance per request

查看:109
本文介绍了Owin上下文中使用每个请求的单个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

app.CreatePerOwinContext(DataContext.Create);

我上面的线来创建此code想出了一个项目数据上下文当我踢一个新的MVC项目5。与此同时,我使用autofac在我注册商的依赖注入每个请求的单个实例。

I have the above line to create a data context this code came with project when i kick a new MVC 5 project. At the same time, i am using autofac to inject single instance per request in my dependency registrar.

<$c$c>builder.RegisterType<DataContext>().As<IDbContext>().InstancePerRequest();

什么是使用owin和DI容器的最佳方式?

What is the best way to use owin and DI container?

我有有一个称为静态方法的DataContext类创建如上面这个休息的时候我尝试在例如数据库类注入的记录器。

I have a DataContext class which has a static Method called Create as above and this break when I try to inject a logger in a database class for example.

我也有兴趣在一个示例项目如果有的话,证明DI和owin在同一个项目。

I am also interested in a sample project if any , demonstrating DI and owin in the same project.

推荐答案

如果你不取由OWIN中间件创建的实例,而是注入上下文到您的控制器,那么你就可以放心地将其删除。只要记住相应地更新脚手架控制器。

If you're not fetching the instance created by the OWIN middleware, and instead injecting your context into your controllers, then you can safely remove it. Just remember to update the scaffolded controllers accordingly.

这篇关于Owin上下文中使用每个请求的单个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆