Description
Firstly, I would like to thank you very much for your work on this package. I am using it combined with IdentityServer in order to support multi-tenancy, however I am experiencing a NullReferenceException
caused by the MultiTentantContext
being null in the HttpContext.Response.OnStarting
function on sign out. I have extended IdentityServer's ConfigurationDbContext
to be multi-tenanted and it is the code here on sign out where the MultiTenantConfigurationDbContext
is unable to get the TenantInfo
because the MultiTentantContext
is null. Interestingly, it only seems to be during sign out that the MultiTentantContext
is null in the HttpContext.Response.OnStarting
function, which makes me wonder if maybe there is something going on with the application's threads during sign out that doesn't play nicely with the AsyncLocal
here. I have created a minimal reproducible example here with steps in the readme and I would really appreciate any pointers that you might be able to provide to help overcome this issue.
app.Use(async (context, next) =>
{
context.Response.OnStarting(() =>
{
// This accessor does not have a multi-tenant context during sign-out.
var accessor = context.RequestServices.GetRequiredService<IMultiTenantContextAccessor<SampleTenantInfo>>();
return Task.CompletedTask;
});
// This accessor has a multi-tenant context during sign-out.
var accessor = context.RequestServices.GetRequiredService<IMultiTenantContextAccessor<SampleTenantInfo>>();
await next();
});
Activity