I am implementing a custom user store where my users provider lives in a separate service which I am reaching out using messaging.
The thing is GetProfileDataAsync
and IsActiveAsync
are getting called too many times (about 3 times each) causing messaging process to be launched each time.
Here is a simple implementation of IProfileService.
public class IdentityProfileService : IProfileService
{
private readonly UserManager<ApplicationUser> _userManager;
public IdentityProfileService (UserManager<ApplicationUser> userManager)
{
_userManager = userManager;
}
public async Task GetProfileDataAsync(ProfileDataRequestContext context)
{
var user = await _userManager.FindBySubjectIdAsync(context.Subject.GetSubjectId());
if (user != null)
{
context.IssuedClaims = user.Claims;
}
}
public async Task IsActiveAsync(IsActiveContext context)
{
var sub = context.Subject.GetSubjectId();
var user = await _userManager.FindByIdAsync(sub);
context.IsActive = user != null;
}
}
My question is:
Is there a way to minimize the number of these calls? or can I check for some info that's existence means that there is no need to call _userManager.FindBySubjectIdAsync
again?