[DoNotMerge] BranchWithServices: Failing test for resolving IHttpContextAccessor#139
[DoNotMerge] BranchWithServices: Failing test for resolving IHttpContextAccessor#139damianh wants to merge 3 commits intoWebApiContrib:masterfrom damianh:branch-with-services
Conversation
…activated in a branch.
… the inner container.
|
there is a narrow set of services that are owned by the HostingApplication https://github.com/aspnet/Hosting/blob/cd3f58bed7234ed5035a995c8688dccd6706b584/src/Microsoft.AspNetCore.Hosting/Internal/HostingApplication.cs#L35
That is why the code you commented out fixes the test. In the IdSrv case, it normally registers the accessor silently, as its own dependency. But if you do |
|
Ok I think I get the explanation why. Which basically means this isn't going to work? |
|
no it works, you can issue and consume tokens, build isolated branches as you wish. it just means since your application is effectively a main app + n child apps (service providers), the HttpContext is always owned and initialized from the main (entry) app. I don't think this is unreasonable too, since you get into the branch via the main app anyway |
|
Yep understood and agreed. Child app containers will need to reach into the main app container for the HttpContextAccessor but that's where the integration stops. I think this implementation is superior as it sets up the default common services, works with startup classes and wires in the IHttpContextAccessor if the main ("root") container has the service registered. Thanks for the discussion and pointer @filipw :) |
|
excellent, thanks! overall you are absolutely right, this code could easily be improved to handle i.e. Startup classes. |
Been exploring
UseBranchWithServicesand not entirely sure am doing it write. Here I added a test project for WebApiContrib.Core and failing test to show resolution of a service failing. Discovered this when attempting to use Identity Server in a branch and was getting ANEs and NREs from deep within it.It's not clear whether one should be passing the IHttpContextAccessor into the branch's container. And if one should, what else is missing?