Nowin icon indicating copy to clipboard operation
Nowin copied to clipboard

Nowin not providing "host.OnAppDisposing" CancellationToken

Open pysco68 opened this issue 9 years ago • 7 comments

Hello,

I'm currently trying to migrate an existing OWIN application to be hosted with Nowin. It worked mostly flawlessly (and with good performance results). However on of the last missing pieces is that Nowin seemingly doesn't provide a CancellationToken under the key host.OnAppDisposing in the application dictionary.

This cancellation token can be used to hook into the disposal process of the application, which can be very useful to dispose things like singletons that were instantiated during the web-application's setup, whitout having to build-up too much messy code.

If you could pinpoint where I should look at to implement the missing parts I'd be happy to contribute to this great project!

Here's some information about the topic:

  • https://msdn.microsoft.com/en-us/library/microsoft.owin.builderproperties.appproperties.onappdisposing%28v=vs.113%29.aspx
  • http://stackoverflow.com/questions/23317965/in-self-hosted-owin-web-api-how-to-run-code-at-shutdown

pysco68 avatar Jun 29 '15 08:06 pysco68

Hi,

This is actually not really part of official Owin standart, so it would be nice is you would add it if you need it :-) I think all changes should be limited to https://github.com/Bobris/Nowin/blob/master/Nowin/OwinServerFactory.cs and https://github.com/Bobris/Nowin/blob/master/Nowin/OwinKeys.cs

Bobris avatar Jun 29 '15 14:06 Bobris

I'd really like to give this a try (or even better implement server.OnDispose as they are mentioned in the official specification: https://github.com/owin/owin/blob/master/CommonKeys.md). I've looked at the code for some while now, and I struggle a bit to find the right place(s) to put that in.

My question: In my understanding the CancellationToken should be reachable via both IAppBuilder.Properties and the request environment. Is this a correct interpretation of the specification?

pysco68 avatar Jun 29 '15 15:06 pysco68

It could be in that capabilities dictionary. You get them in each request, but I don't think it should be usefull there for anything (https://github.com/Bobris/Nowin/blob/master/Nowin/OwinEnvironment.Generated.tt#L29), you already have owin.CallCanceled

Bobris avatar Jun 29 '15 16:06 Bobris

And how to find out that server is disposing just subscribe in https://github.com/Bobris/Nowin/blob/master/Nowin/OwinServerFactory.cs#L79

Bobris avatar Jun 29 '15 16:06 Bobris

server.OnInit and server.OnDispose have been standardized. The microsoft key is mentioned as a backward compatibility thing. See https://github.com/owin/owin/issues/27

serialseb avatar Jul 14 '15 15:07 serialseb

@serialseb Problem is that Nowin is just server not host or builder, so I am no sure to which Dictionary I should place this (in per request it would be for sure useless. If you know about some sample implementation I could learn from how to do it, I am also interested.

Bobris avatar Jul 14 '15 19:07 Bobris

startup properties exist during wireup (if you support BuildFunc), and contain all the common keys "available at startup", as per CommonKeys. The env contains startup keys and the http request associated keys.

In other words, anything that ought to be exposed as a startup key ought to be in its own dictionary, and any key per request / response ought to be in the env dictionary, which contains all the startup keys.

The upcoming 1.0.1 spec will clarify those things.

serialseb avatar Sep 01 '15 10:09 serialseb