Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Inject IHttpContextAccessor to CatalogContext's constructor will be destoryed when RevokeAuthenticationEvents.cs handle about CatalogContext's data #938

@Cheunglik

Description

@Cheunglik

if I only inject IHttpContextAccessor In CatalogContext's constructor. It' works!
public CatalogContext(DbContextOptions options, IHttpContextAccessor httpContextAccessor) : base(options)
{
var name = httpContextAccessor.HttpContext?.User.Claims.SingleOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value ?? "";
}
I can get the user's ID in the context's consturctor if user logged on.
https://github.com/Cheunglik/eShopOnWeb/commit/5ca53d7675bc98baf0ff9c5e1d27c16e16f922ea
withUserClaims

But I add some's data handling like ICatalogItemViewModelService in RevokeAuthenticationEvents
public RevokeAuthenticationEvents(IMemoryCache cache, ILogger logger, ICatalogItemViewModelService catalogItemViewModelService)
{
_cache = cache;
_logger = logger;
_catalogItemViewModelService = catalogItemViewModelService;
}
https://github.com/Cheunglik/eShopOnWeb/commit/5ca53d7675bc98baf0ff9c5e1d27c16e16f922ea
I can not get the user'ID in the context's consturctor even the user logged on.
withoutUserClaims

I just fork from the original main braches https://github.com/dotnet-architecture/eShopOnWeb and add two simple comments. It 's so easy to reproduce it.
In fact I want to handler some data in cookie's CookieAuthenticationEvents, I will add some tenant's records in user.claims.
When user request controller => service=> repository => dbcontext.
The dbContext can apply modelBuilder.Entity.HasQueryFilter(from userclaim's property) to isolate different tenant's record.

Please assist with the possibilities.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions