Code Monkey home page Code Monkey logo

Comments (15)

srogovtsev avatar srogovtsev commented on July 19, 2024 1

Yes, I want to be responsible for scope disposal. So, you mean the startup would look like

app
   .Use((ctx, next) =>
   {
      ctx.SetAutofacLifetimeScope(myScopeGetter());
      return next();
   }
   .UseAutofacLifetimeScopeInjector(rootContainer)
   .UseMiddlewareFromContainer<MyMiddleware>();

...and UseAutofacLifetimeScopeInjector (RegisterAutofacLifetimeScopeInjector, in fact) will check whether the scope exists, and if it does, will simply call next() instead of creating/disposing its own scope?

Totally fine by me.

from autofac.owin.

tillig avatar tillig commented on July 19, 2024

Why not just insert your own middleware that creates the lifetime scope into the pipeline before the Autofac middleware runs? OWIN won't create a lifetime scope if it's already present.

You could basically copy/paste the AutofacMiddleware class, have it call your factory, and then add it to the pipeline prior to the AutofacMiddleware itself being added.

from autofac.owin.

srogovtsev avatar srogovtsev commented on July 19, 2024

Constants.OwinLifetimeScopeKey is internal, so I can't inject the scope myself (same with InjectorRegisteredKey).

(yes, actually the minimal change that allows me to fix the problem is to simply make them public)

from autofac.owin.

tillig avatar tillig commented on July 19, 2024

What if we added context.SetAutofacLifetimeScope(ILifetimeScope scope)?

from autofac.owin.

srogovtsev avatar srogovtsev commented on July 19, 2024

This would be nice! But UseMiddlewareFromContainer checks for injector registration, so you'd have to provide something like app.MarkInjectorAsRegistered as well - which is not a problem by me, of course.

So the whole startup would look like this:

app
   .Use((ctx, next) =>
   {
      ctx.SetAutofacLifetimeScope(myScopeGetter());
      return next();
   }
   .MarkInjectorRegistered()
   .UseMiddlewareFromContainer<MyMiddleware>();

from autofac.owin.

tillig avatar tillig commented on July 19, 2024

Couldn't we just add a null check here? Like, if lifetime scope isn't already set, create it; otherwise just don't do anything.

from autofac.owin.

tillig avatar tillig commented on July 19, 2024

Also, when did you want to dispose of the scope? If you set your own scope, would that mean you're responsible for disposing it? (I'm guessing so.) In that case, it'd be like "if the scope is set, just await next() otherwise do the using/create lifetime scope thing."

from autofac.owin.

srogovtsev avatar srogovtsev commented on July 19, 2024

Should I draft up a pull-request for this?

from autofac.owin.

tillig avatar tillig commented on July 19, 2024

Sure, that'd rock.

from autofac.owin.

srogovtsev avatar srogovtsev commented on July 19, 2024

I ended up creating two pull requests, for different variants of syntax (for all I know, you can adopt both, they do not contradict each other).

from autofac.owin.

tillig avatar tillig commented on July 19, 2024

I think both enhancements are good. I'll pull them both in. You rock! Thanks!

from autofac.owin.

tillig avatar tillig commented on July 19, 2024

I have both PRs merged and semver updated to 4.1.0. Building, published to MyGet, ready to go. You mentioned you wanted to do one more look at the code to make sure it's all good, so please do and let me know if there are more changes or if it's ready.

If it's ready, I'll push it as 4.1.0 to NuGet and close this issue.

from autofac.owin.

srogovtsev avatar srogovtsev commented on July 19, 2024

from autofac.owin.

srogovtsev avatar srogovtsev commented on July 19, 2024

Done it, see #14. Sorry it took me so long, I've finally remembered what it was that I wanted to add on Saturday - an extension method to compensate for the fact that externally created lifetime scope doesn't have IOwinContext registered.

from autofac.owin.

tillig avatar tillig commented on July 19, 2024

Pushed to NuGet as 4.1.0. Thanks again!

from autofac.owin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.