Dependency injection OWIN启动类
有人能告诉我OWIN创业班的确切角色吗。基本上就是我想要的:Dependency injection OWIN启动类,dependency-injection,owin,Dependency Injection,Owin,有人能告诉我OWIN创业班的确切角色吗。基本上就是我想要的: 它的目的是什么 当它被调用时,它只是一次或每次请求 这是配置依赖项注入库的好地方吗 Owin设计为可插拔设计。您可以从配置中更改/替换一组服务。例如,在以下配置中,我有 启用webapi 启用信号机 启用基于属性的信令路由 配置的默认依赖项解析程序 用自定义记录器替换日志记录服务 因此,通过这种方式,您可以配置完整的配置。它在启动时只调用一次。您可以在这里设置/使用依赖项解析器并进行配置,但这主要取决于您的总体设计 public
- 它的目的是什么
- 当它被调用时,它只是一次或每次请求
- 这是配置依赖项注入库的好地方吗
- 启用webapi
- 启用信号机
- 启用基于属性的信令路由
- 配置的默认依赖项解析程序
- 用自定义记录器替换日志记录服务
- Owin设计为可插拔设计。您可以从配置中更改/替换一组服务。例如,在以下配置中,我有
public class OwinStartup
{
//initialize owin startup class and do other stuff
public void Configuration(IAppBuilder app)
{
app.UseWelcomePage("/");
//var container = new UnityContainer();
HttpConfiguration httpConfiguration = new HttpConfiguration();
httpConfiguration.Routes.MapHttpRoute(
name: "MyDefaultApi",
routeTemplate: "api/v2/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
//Maps the attribute based routing
httpConfiguration.MapHttpAttributeRoutes();
//Set the unity container as the default dependency resolver
httpConfiguration.DependencyResolver = new UnityWebApiDependencyResolver(new UnityContainer());
//replace (or add) the exception logger service to custom Logging service
httpConfiguration.Services.Replace(typeof(IExceptionLogger), new ExLogger());
app.UseWebApi(httpConfiguration);
//Add Signalr Layer
app.MapSignalR(new HubConfiguration
{
EnableJSONP = true,
EnableDetailedErrors = true
});
}
public class ExLogger : ExceptionLogger
{
public override void Log(ExceptionLoggerContext context)
{
base.Log(context);
//do something
}
}
}
参考这个,谢谢你的指点,我已经看过了。你能告诉我这是配置DI的好地方吗?如果不是的话,我应该在哪里配置?我没有得到的是什么是DI?依赖注入(Autofac,Unity)你使用哪种技术?i、 e.Net:MVC还是elz