-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
36 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
src/Application/Features/Tenants/EventHandlers/TenantChangedEventHandler.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,47 @@ | ||
using AutoMapper; | ||
using AutoMapper.QueryableExtensions; | ||
using CleanArchitecture.Blazor.Application.Features.Identity.Dto; | ||
using LazyCache; | ||
|
||
namespace CleanArchitecture.Blazor.Infrastructure.Services.Identity; | ||
public class UserDataProvider : IUserDataProvider | ||
{ | ||
private const string CACHEKEY = "ALL-ApplicationUserDto"; | ||
private readonly IAppCache _cache; | ||
private readonly IMapper _mapper; | ||
private readonly UserManager<ApplicationUser> _userManager; | ||
public List<ApplicationUserDto> DataSource { get; private set; } | ||
|
||
public event Action? OnChange; | ||
|
||
public UserDataProvider( | ||
IAppCache cache, | ||
IMapper mapper, | ||
IServiceScopeFactory scopeFactory) | ||
{ | ||
_cache = cache; | ||
_mapper = mapper; | ||
var scope = scopeFactory.CreateScope(); | ||
_userManager = scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>(); | ||
DataSource = new List<ApplicationUserDto>(); | ||
} | ||
public void Initialize() | ||
{ | ||
DataSource = _userManager.Users.Include(x => x.UserRoles).ThenInclude(x => x.Role).ProjectTo<ApplicationUserDto>(_mapper.ConfigurationProvider).OrderBy(x=>x.UserName).ToList(); | ||
DataSource = _cache.GetOrAdd(CACHEKEY,()=>_userManager.Users.Include(x => x.UserRoles).ThenInclude(x => x.Role).ProjectTo<ApplicationUserDto>(_mapper.ConfigurationProvider).OrderBy(x=>x.UserName).ToList()); | ||
OnChange?.Invoke(); | ||
} | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
DataSource =await _userManager.Users.Include(x => x.UserRoles).ThenInclude(x => x.Role).ProjectTo<ApplicationUserDto>(_mapper.ConfigurationProvider).OrderBy(x => x.UserName).ToListAsync(); | ||
DataSource =await _cache.GetOrAddAsync(CACHEKEY,()=> _userManager.Users.Include(x => x.UserRoles).ThenInclude(x => x.Role).ProjectTo<ApplicationUserDto>(_mapper.ConfigurationProvider).OrderBy(x => x.UserName).ToListAsync()); | ||
OnChange?.Invoke(); | ||
} | ||
|
||
public Task Refresh() | ||
public async Task Refresh() | ||
{ | ||
_cache.Remove(CACHEKEY); | ||
DataSource = await _cache.GetOrAddAsync(CACHEKEY, () => _userManager.Users.Include(x => x.UserRoles).ThenInclude(x => x.Role).ProjectTo<ApplicationUserDto>(_mapper.ConfigurationProvider).OrderBy(x => x.UserName).ToListAsync()); | ||
OnChange?.Invoke(); | ||
return Task.CompletedTask; | ||
|
||
} | ||
} |