Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anatomy of an OWIN Startup

What are all the hooks on the OWIN Startup class? Information on these is scarce.

For example, one required hook on every Startup class is that it should have a Configuration method. This information can be gathered from the Microsoft documentation.

class Startup
{
    public void Configuration(IAppBuilder appBuilder)
    {
        ...
    }
}

What is the rationale behind not having an IOwinStartup interface or OwinStartup base class in the framework?

interface IOwinStartup
{
    void Configuration(IAppBuilder appBuilder);
}

How do I perform cleanup for my OWIN-based application? Does OWIN detect a Dispose method on the Startup class, similar to how it detects a Configuration method?

After a lot of searching I found this related question: In self-hosted OWIN Web API, how to run code at shutdown? It's not clear how the peopled who answered that question arrived at the necessary information. Am I missing critical documentation or are these details of the OWIN Startup class as elusive as they seem?

like image 656
Timothy Shields Avatar asked Dec 05 '14 04:12

Timothy Shields


People also ask

What is OWIN startup?

Open Web Interface for . NET (OWIN) defines an abstraction between . NET web servers and web applications. By decoupling the web server from the application, OWIN makes it easier to create middleware for . NET web development.

Which are parts of OWIN application?

OWIN application has different working parts like (Host, Server, Middleware Pipeline, Application).

What is OWIN framework?

OWIN allows web apps to be decoupled from web servers. It defines a standard way for middleware to be used in a pipeline to handle requests and associated responses. ASP.NET Core applications and middleware can interoperate with OWIN-based applications, servers, and middleware.


1 Answers

It's not so much a "hook" as it is a convention. There is a good article on this here:

http://www.asp.net/aspnet/overview/owin-and-katana/owin-startup-class-detection

As for why there is no interface, most likely it's because there was no need to lock it down to that level. This is largely reflection based, and you can specify the class and method to use for startup by various configuration parameters.

In the case of WebAPI in the example you link to, you can do so in the WebApp.Start method, and specify StartOptions with the name of the method to use, but the convention is Configuration.

Cleanup can be accomplished by getting the cancelation token. This information is in the documentation, which is linked from the examples you show. I'm not sure I understand how you arrive at the conclusion that the documentation is missing when it's clearly not.

http://msdn.microsoft.com/en-us/library/microsoft.owin.builderproperties.appproperties.onappdisposing(v=vs.113).aspx

Certainly, it's missing elaboration and examples... but there are a lot of blog entries about this stuff...

You may also want to read the OWIN specification:

http://owin.org/spec/spec/owin-1.0.0.html

like image 200
Erik Funkenbusch Avatar answered Sep 28 '22 01:09

Erik Funkenbusch