What is the call of a class called the OwinStartup attribute called?

After adding the nuget packages for OWIN, if you add the attribute:

[assembly: OwinStartup(typeof(MyProject.Startup))]

Then the class method MyProject.Startup

public void Configuration(IAppBuilder app)

called out. How it's called? The only reference to OWIN in web.config is to redirect assembly bindings. In my project, there is no other link to the http module that could recognize this attribute. If I look at the stack trace, I see the lines:

Microsoft.Owin.Host.SystemWeb.dll!Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(System.Web.HttpApplication context) Unknown
System.Web.dll!System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(System.IntPtr appContext, System.Web.HttpContext context, System.Reflection.MethodInfo[] handlers)  Unknown

This shows that OWIN is registered as an event subscription with IIS, but how did this happen? Is it hard to bake in a framework that it is looking for a link to an assembly?

+4
source share
1 answer

ASP.NET 4 PreApplicationStartMethodAttribute . - , Application_Start, . , . , ASP.NET , Application_Start.

:

[assembly: PreApplicationStartMethod(typeof(SomeClassLib.Initializer), "Initialize")]

, - . void , , :

public static class Initializer
{
  public static void Initialize() { 
    // Whatever can we do here?
  }
}

PreApplicationStartMethod :

[assembly: PreApplicationStartMethod(typeof(PreApplicationStart), "Initialize")]

Initialize() PreApplicationStart:

public static class PreApplicationStart
{
    private const string TraceName = "Microsoft.Owin.Host.SystemWeb.PreApplicationStart";

    /// <summary>
    /// Registers the OWIN request processing module.
    /// </summary>
    public static void Initialize()
    {
        try
        {
            if (OwinBuilder.IsAutomaticAppStartupEnabled)
            {
                HttpApplication.RegisterModule(typeof(OwinHttpModule));
            }
        }
        catch (Exception exception1)
        {
            Exception exception = exception1;
            ITrace trace = TraceFactory.Create("Microsoft.Owin.Host.SystemWeb.PreApplicationStart");
            trace.WriteError(Resources.Trace_RegisterModuleException, exception);
            throw;
        }
    }
}

HttpApplication.RegisterModule(typeof(OwinHttpModule));

OwinHttpModule OwinBuilder OwinAppContext, Startup .

+7

All Articles