You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 23, 2024. It is now read-only.
Inject IHttpContextAccessor to CatalogContext's constructor will be destoryed when RevokeAuthenticationEvents.cs handle about CatalogContext's data
#938
Open
Cheunglik opened this issue
Sep 9, 2023
· 0 comments
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
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.
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.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
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.
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.
The text was updated successfully, but these errors were encountered: