有人可以告诉我OWIN启动课的确切作用。基本上我在寻找:
答案 0 :(得分:1)
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
}
}
}