I am trying to create an OwinMiddleware object to register in the pipeline to pull some requests from an incoming request and apply them to a service in our service container. The result would be that a service that requires authorization, which we use in the controllers, will arrive in advance, which means that the controllers no longer need to take out the headers and authorization principles, and I can remove a lot of plumbing, which transfers these values to several layers.
We use DependencyInjection (Microsoft.Extensions.DependencyInjection), and, more importantly, this outreach service is taxed, which means that it needs to be created and destroyed per request (i.e., otherwise it could have accidentally used loans from previous queries). Its collection is done using a fairly simple implementation of IDependencyResolver, which uses a ServiceCollection. The survey works through the .BeginScope () method, which I don’t quite understand, because I can’t find the sources that actually call .BeginScope () through the HttpConfiguration.ID dependency of Resolver, I’m kind of guessing what it is, but not completely. It works well.
Now the problem with the object inherited from OwinMiddleware is that I cannot get it to exchange information with the corresponding cloud object through IDependencyResolver.
Since I do not control the creation of the OwinMiddleware object, all I can do is specify the service I want to interact with in the constructor. However, this seems useless because it doesn't seem to give me the same instance of the object later in the pipeline than I do here (I assume because it is limited?).
Even if I put IDependencyResolver in the constructor, I still do not get the correct instance of my service. I can check if middleware is running.
, Invoke() OwinMiddleware , . , , , . . Owin lib (v3) :
public abstract Task Invoke(IOwinContext context);
, , - . ? - , ?
, , , aspnet 5, , , . , ?
... , . OwinMiddleware OwinMiddleware, DI .
, , : () . Resolver (-, MVC Web API). - , , , Id . , -, ASP.NET 5, ...