question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OWIN-compatible implementation for "PerWebRequest" lifestyle

See original GitHub issue

The PerWebRequest HttpModule has served everyone well for applications hosted in IIS, to enable “Per webrequest” lifestyle.

However, in recent years, OWIN has become more popular and with it, the ability to self-host websites. Windsor’s PerWebRequestLifeStyle is incompatible with OWIN’s self-hosting mechanism, as HTTP modules only work in the IIS pipeline.

Some OWIN-compatible implementations of this lifestyle have been hacked together, see StackOverflow and GitHub.

However I think it would be best if such implementation was cleaned up, put under test, and integrated with the main project here. It would be a nice bonus if the same configuration syntax could be used as well (i.e. calling LifestylePerWebRequest()). Maybe there could be some magic to make it work under all hosting scenarios.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:73 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Jun 27, 2017

@mario-d-s - I was thinking we start a series of PR’s to start moving the DesktopCLR PerWebRequestLifestyleModuleRegistration stuff out of Windsor and into facilities(or something else). It is still there and supports the FEATURE_SYSTEM_WEB . The reason I say this is there has been a significant effort to migrate this windsor to dotnet core and it presents different challenges for Windsor’s public API when it comes to lifestyle management. My vote is that we talk about how we would abstract this out whilst implementing an OWIN compatible version at the same time? What do you think?

1reaction
ghostcommented, Jun 14, 2017

@mario-d-s: I remember reading about this many moons ago, cannot for the life of me remember why though 😃

@jonorossi: I did come across the use of AsyncLocal here. I must have missed that bit in the netcore branch when my internet was borked.

Checking out some middleware implementations would be as simple as creating an extension that goes something like this?


app.Use(new Func<AppFunc, AppFunc>(next => (async env =>
{
    myWindsorContainer.BeginScope();
    await next.Invoke(env);
    myWindsorContainer.EndScope()
})));

You could then wrap it in a tidy extension method.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Castle Windsor PerWebRequest LifeStyle and ...
I'm registering some components related to Linq2Sql using PerWebRequest lifestyle. I see them get created, but they get destroyed before my ...
Read more >
Using Castle Windsor's PerWebRequest lifestyle with ASP ...
This is the purpose of the PerWebRequest lifestyle. If you try that with ASP.NET MVC on IIS7, you are likely to receive the...
Read more >
Castle: PerWebRequestLifeStyle won't work from ... - Alanta
I've implemented a workaround by customizing the implementation of the lifestyle manager. This work-around falls back to the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found