-
Notifications
You must be signed in to change notification settings - Fork 926
React.NET with self hosting and PerRequestSingletons #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks @shaunol, glad you like it! I've never tried OWIN myself and actually didn't know of its existence until recently. I wonder how other IoC containers handle it. I use Simple Injector on my own site, and my previous workplace used Ninject. I wonder if either of them have a OWIN lifetime provider. The idea of registering everything at startup is that it it's fine for the initial registration to be expensive since it's only done once. I've seen a few mentions of |
Does OWIN itself have a dependency injection framework, and does it have the idea of a per-request registration? If so, the other option would be to register all of ReactJS.NET's classes in OWIN's container rather than the TinyIoC bundled with ReactJS.NET |
I'll do some digging to see if I can get some insight into how others handle the context. The OWIN assemblies themselves don't appear to have any kind of IoC container on the surface. Of course with OWIN request handling you can do your own per-request anything so if I had a way to provide my context within the pipeline rather than exposing it statically, it would seem more logical. I will investigate if there's something for me to write that can provide this interface regardless. I can't use the GetOwinContext() because I'm not using WebApi, whose pipeline itself would provide a reference its HttpContext. I'm not sure how to write that particular piece of code (ensuring my statically exposed Context is indeed per request). See here http://blogs.msdn.com/b/webdev/archive/2014/02/18/introducing-asp-net-project-helios.aspx for the particular setup I'm using. Though I'm using the SelfHost package instead of IIS - but both should have the same issue. |
It looks like someone has solved the IoC problem https://github.com/DotNetDoodle/DotNetDoodle.Owin.Dependencies which I came across from http://stackoverflow.com/a/20079215 I will have a look through that code and see if it can be applied to this problem. |
Fixed with #69 |
Hi there, first of all thanks for the great library. It's useful to have familiar tooling when learning new things.
I'm running React.NET inside a Microsoft.Owin self hosted environment. I've picked out the parts I needed from existing sources and seemed to get an environment up and running reasonably painlessly, including using RazorEngine and server-side rendering.
My only issue is how can I inject the current request context into the IoC container correctly? In the React.Web example you've created a HttpContextLifetimeProvider which is speaking directly to the Asp.Net static HttpContext property. In Owin we have no such thing and instead must pass our context from inside the request pipeline.
Because the current strategy of creating PerRequest object instances relies on creating the instance creation Func on application startup, you never get an opportunity to create an instance of the LifeTimeProvider with a specific context. It seems quite engrained in the IoC implementation too not to be able to handle this.
Are there any plans to handle this and do you have any suggestions for what I can do in the meantime?
Cheers
Edit: Example of a potential Owin LifetimeProvider based on the original HttpContextLifeTimeProvider with context injected constructor: https://gist.github.com/shaunol/11238848
The text was updated successfully, but these errors were encountered: