diff --git a/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache.Storage/README.md b/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache.Storage/README.md new file mode 100644 index 000000000..7c54883d0 --- /dev/null +++ b/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache.Storage/README.md @@ -0,0 +1,47 @@ +[中](README.zh-CN.md) | EN + +## Masa.Contrib.Authentication.Oidc.Cache.Storage + +Effect: + +Use IClientStore and IResourceStore get oidc resources and client data. + +```c# +├── IClientStore +├── IResourceStore +``` + +Example: + +```C# +Install-Package Masa.Contrib.Authentication.Oidc.Cache.Storage +``` + +```C# +builder.Services.AddOidcCacheStorage(nnew RedisConfigurationOptions +{ + Servers = new List + { + new RedisServerOptions + { + Host="127.0.0.1", + Port=6379 + } + }, + DefaultDatabase = 0, + Password = "", +}); +``` + +How to use: + +```c# +var app = builder.Build(); + +app.MapGet("/GetClient", async ([FromServices] IClientStore store) => +{ + return await store.FindClientByIdAsync("clientId"); +}); + +app.Run(); +``` diff --git a/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache.Storage/README.zh-CN.md b/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache.Storage/README.zh-CN.md new file mode 100644 index 000000000..7d050dabb --- /dev/null +++ b/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache.Storage/README.zh-CN.md @@ -0,0 +1,47 @@ +中 | [EN](README.md) + +## Masa.Contrib.Authentication.Oidc.Cache.Storag + +作用: + +通过IClientStore和IResourceStore获取资源和客户端的相关数据 + +```c# +├── IClientStore +├── IResourceStore +``` + +用例: + +```C# +Install-Package Masa.Contrib.Authentication.Oidc.Cache.Storag +``` + +```C# +builder.Services.AddOidcCacheStorage(nnew RedisConfigurationOptions +{ + Servers = new List + { + new RedisServerOptions + { + Host="127.0.0.1", + Port=6379 + } + }, + DefaultDatabase = 0, + Password = "", +}); +``` + +如何使用: + +```c# +var app = builder.Build(); + +app.MapGet("/GetClient", async ([FromServices] IClientStore store) => +{ + return await store.FindClientByIdAsync("clientId"); +}); + +app.Run(); +``` diff --git a/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache/Caches/ClientCache.cs b/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache/Caches/ClientCache.cs index 3e9acd125..3cb9e950a 100644 --- a/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache/Caches/ClientCache.cs +++ b/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache/Caches/ClientCache.cs @@ -17,6 +17,13 @@ public ClientCache(IMemoryCacheClient memoryCacheClient) return await _memoryCacheClient.GetAsync(FormatKey(clientId)); } + public async Task> GetListAsync(IEnumerable clientIds) + { + var keys = clientIds.Select(clientId => FormatKey(clientId)).ToArray(); + var clients = await _memoryCacheClient.GetListAsync(keys); + return clients.Where(client => client is not null).ToList()!; + } + public async Task SetAsync(Client client) { await _memoryCacheClient.SetAsync(FormatKey(client), client.ToModel()); diff --git a/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache/README.md b/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache/README.md new file mode 100644 index 000000000..888728030 --- /dev/null +++ b/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache/README.md @@ -0,0 +1,49 @@ +[中](README.zh-CN.md) | EN + +## Masa.Contrib.Authentication.Oidc.Cache + +Effect: + +Use the second level cache to operate resources and client data. + +```c# +├── ApiResourceCache +├── ApiScopeCache +├── ClientCache +├── IdentityResourceCache +``` + +Example: + +```C# +Install-Package Masa.Contrib.Authentication.Oidc.Cache +``` + +```C# +builder.Services.AddOidcCache(nnew RedisConfigurationOptions +{ + Servers = new List + { + new RedisServerOptions + { + Host="127.0.0.1", + Port=6379 + } + }, + DefaultDatabase = 0, + Password = "", +}); +``` + +How to use: + +```c# +var app = builder.Build(); + +app.MapGet("/GetClient", async ([FromServices] IClientCache cache) => +{ + return await cache.GetAsync("clientId"); +}); + +app.Run(); +``` diff --git a/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache/README.zh-CN.md b/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache/README.zh-CN.md new file mode 100644 index 000000000..6e29ffc4c --- /dev/null +++ b/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache/README.zh-CN.md @@ -0,0 +1,49 @@ +中 | [EN](README.md) + +## Masa.Contrib.Authentication.Oidc.Cache + +作用: + +使用二级缓存来操作资源和客户端数据。 + +```c# +├── ApiResourceCache +├── ApiScopeCache +├── ClientCache +├── IdentityResourceCache +``` + +用例: + +```C# +Install-Package Masa.Contrib.Authentication.Oidc.Cache +``` + +```C# +builder.Services.AddOidcCache(nnew RedisConfigurationOptions +{ + Servers = new List + { + new RedisServerOptions + { + Host="127.0.0.1", + Port=6379 + } + }, + DefaultDatabase = 0, + Password = "", +}); +``` + +如何使用: + +```c# +var app = builder.Build(); + +app.MapGet("/GetClient", async ([FromServices] IClientCache cache) => +{ + return await cache.GetAsync("clientId"); +}); + +app.Run(); +``` diff --git a/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache/Utils/CollectionExtensions.cs b/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache/Utils/CollectionExtensions.cs index f4f63f068..b52bd7fb3 100644 --- a/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache/Utils/CollectionExtensions.cs +++ b/src/Authentication/Masa.Contrib.Authentication.Oidc.Cache/Utils/CollectionExtensions.cs @@ -28,7 +28,7 @@ public static void Remove(this ICollection collection, T data, Func(this ICollection collection, IEnumerable datas, Func keySelector) { - var oldDatas = collection.Where(item => datas.Any(data => keySelector(data).Equals(keySelector(item)))); + var oldDatas = collection.Where(item => datas.Any(data => keySelector(data).Equals(keySelector(item)))).ToList(); if (oldDatas.Count() > 0) { foreach (var oldData in oldDatas) @@ -40,7 +40,7 @@ public static void RemoveRange(this ICollection collection, IEnumerable public static void Remove(this ICollection collection, Func condition) { - var datas = collection.Where(condition); + var datas = collection.Where(condition).ToList(); if(datas.Count() > 0) { foreach (var data in datas) diff --git a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Caches/SyncCache.cs b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Caches/SyncCache.cs index 936e9c3ad..0bcd1329f 100644 --- a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Caches/SyncCache.cs +++ b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Caches/SyncCache.cs @@ -9,7 +9,7 @@ public class SyncCache IApiResourceCache _apiResourceCache; IApiScopeCache _apiScopeCache; IIdentityResourceCache _identityResourceCache; - OidcDbContext _context; + DbContext _context; public SyncCache(IClientCache clientCache, IApiResourceCache apiResourceCache, IApiScopeCache apiScopeCache, IIdentityResourceCache identityResourceCache, OidcDbContext context) { @@ -17,7 +17,7 @@ public SyncCache(IClientCache clientCache, IApiResourceCache apiResourceCache, I _apiResourceCache = apiResourceCache; _apiScopeCache = apiScopeCache; _identityResourceCache = identityResourceCache; - _context = context; + _context = context.Dbcontext; } internal async Task SyncApiResourceCacheAsync(int id) @@ -56,7 +56,7 @@ internal async Task RemoveIdentityResourceCacheAsync(IdentityResource identityRe await _identityResourceCache.RemoveAsync(identityResource); } - private async Task ResetAsync() + public async Task ResetAsync() { var clients = await ClientQuery().ToListAsync(); var apiScopes = await ApiScopeQuery().ToListAsync(); diff --git a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/DbContexts/OidcDbContext.cs b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/DbContexts/OidcDbContext.cs index 3165b482b..7d39a137c 100644 --- a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/DbContexts/OidcDbContext.cs +++ b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/DbContexts/OidcDbContext.cs @@ -3,15 +3,17 @@ namespace Masa.Contrib.Authentication.Oidc.EntityFrameworkCore.DbContexts; -public class OidcDbContext : DbContext +public class OidcDbContext { - public OidcDbContext(DbContextOptions options) : base(options) + public DbContext Dbcontext { get; set; } + + public OidcDbContext(DbContext dbcontext) { + Dbcontext = dbcontext; } - protected override void OnModelCreating(ModelBuilder modelBuilder) + public static implicit operator DbContext(OidcDbContext context) { - modelBuilder.HasDefaultSchema("oidc"); - modelBuilder.ApplyConfigurationsFromAssembly(typeof(OidcDbContext).Assembly); + return context.Dbcontext; } } diff --git a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/README.md b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/README.md new file mode 100644 index 000000000..cfa90b183 --- /dev/null +++ b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/README.md @@ -0,0 +1,39 @@ +[中](README.zh-CN.md) | EN + +## Masa.Contrib.Authentication.Oidc.EntityFrameworkCore + +Effect: + +Use the Repository to operate the Oidc database + +```c# +├── ApiResourceRepository +├── ApiScopeRepository +├── ClientRepository +├── IdentityResourceRepository +├── UserClaimRepository +``` + +Example: + +```C# +Install-Package Masa.Contrib.Authentication.Oidc.EntityFrameworkCore +``` + +```C# +builder.Services.AddOidcDbContext(option => option.UseSqlServer("ConnectionString", + b => b.MigrationsAssembly(migrationsAssembly))); +``` + +How to use: + +```c# +var app = builder.Build(); + +app.MapGet("/GetClients", async ([FromServices] IClientRepository repository) => +{ + return await repository.GetListAsync(); +}); + +app.Run(); +``` diff --git a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/README.zh-CN.md b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/README.zh-CN.md new file mode 100644 index 000000000..20c85efa3 --- /dev/null +++ b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/README.zh-CN.md @@ -0,0 +1,39 @@ +中 | [EN](README.md) + +## Masa.Contrib.Authentication.Oidc.EntityFrameworkCore + +作用: + +通过Repository操作Oidc数据库 + +```c# +├── ApiResourceRepository +├── ApiScopeRepository +├── ClientRepository +├── IdentityResourceRepository +├── UserClaimRepository +``` + +用例: + +```C# +Install-Package Masa.Contrib.Authentication.Oidc.EntityFrameworkCore +``` + +```C# +builder.Services.AddOidcDbContext(option => option.UseSqlServer("ConnectionString", + b => b.MigrationsAssembly(migrationsAssembly))); +``` + +如何使用: + +```c# +var app = builder.Build(); + +app.MapGet("/GetClients", async ([FromServices] IClientRepository repository) => +{ + return await repository.GetListAsync(); +}); + +app.Run(); +``` diff --git a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/ApiResourceRepository.cs b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/ApiResourceRepository.cs index 38868fa1e..846f2e75d 100644 --- a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/ApiResourceRepository.cs +++ b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/ApiResourceRepository.cs @@ -6,12 +6,14 @@ namespace Masa.Contrib.Authentication.Oidc.EntityFrameworkCore.Repositories; public class ApiResourceRepository : IApiResourceRepository { SyncCache _cache; - OidcDbContext _context; + DbContext _context; + IRepository _repository; - public ApiResourceRepository(SyncCache cache, OidcDbContext context) + public ApiResourceRepository(SyncCache cache, OidcDbContext context, IRepository repository) { _cache = cache; _context = context; + _repository = repository; } public async Task> GetPaginatedListAsync(int page, int pageSize, Expression>? condition = null) @@ -66,23 +68,23 @@ public async ValueTask AddAsync(ApiResource apiResource) if (exist) throw new UserFriendlyException($"ApiResource with name {apiResource.Name} already exists"); - var newApiResource = await _context.AddAsync(apiResource); + var newApiResource = await _repository.AddAsync(apiResource); await _context.SaveChangesAsync(); await _cache.SyncApiResourceCacheAsync(apiResource.Id); - return newApiResource.Entity; + return newApiResource; } public async Task UpdateAsync(ApiResource apiResource) { - var newApiResource = _context.Update(apiResource); + var newApiResource = await _repository.UpdateAsync(apiResource); await _context.SaveChangesAsync(); await _cache.SyncApiResourceCacheAsync(apiResource.Id); - return newApiResource.Entity; + return newApiResource; } public async Task RemoveAsync(ApiResource apiResource) { - _context.Remove(apiResource); + await _repository.RemoveAsync(apiResource); await _context.SaveChangesAsync(); await _cache.RemoveApiResourceCacheAsync(apiResource); } diff --git a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/ApiScopeRepository.cs b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/ApiScopeRepository.cs index 9f4d3039b..c85a850ee 100644 --- a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/ApiScopeRepository.cs +++ b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/ApiScopeRepository.cs @@ -6,12 +6,14 @@ namespace Masa.Contrib.Authentication.Oidc.EntityFrameworkCore.Repositories; public class ApiScopeRepository : IApiScopeRepository { SyncCache _cache; - OidcDbContext _context; + DbContext _context; + IRepository _repository; - public ApiScopeRepository(SyncCache cache, OidcDbContext context) + public ApiScopeRepository(SyncCache cache, OidcDbContext context, IRepository repository) { _cache = cache; _context = context; + _repository = repository; } public async Task> GetPaginatedListAsync(int page, int pageSize, Expression>? condition = null) @@ -64,23 +66,23 @@ public async ValueTask AddAsync(ApiScope apiScope) if (exist) throw new UserFriendlyException($"ApiScope with name {apiScope.Name} already exists"); - var newApiScope = await _context.AddAsync(apiScope); + var newApiScope = await _repository.AddAsync(apiScope); await _context.SaveChangesAsync(); await _cache.SyncApiScopeCacheAsync(apiScope.Id); - return newApiScope.Entity; + return newApiScope; } public async Task UpdateAsync(ApiScope apiScope) { - var newApiScope = _context.Update(apiScope); + var newApiScope = await _repository.UpdateAsync(apiScope); await _context.SaveChangesAsync(); await _cache.SyncApiScopeCacheAsync(apiScope.Id); - return newApiScope.Entity; + return newApiScope; } public async Task RemoveAsync(ApiScope apiScope) { - _context.Remove(apiScope); + await _repository.RemoveAsync(apiScope); await _context.SaveChangesAsync(); await _cache.RemoveApiScopeCacheAsync(apiScope); } diff --git a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/ClientRepository.cs b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/ClientRepository.cs index 0e622d7d8..7705f911f 100644 --- a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/ClientRepository.cs +++ b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/ClientRepository.cs @@ -6,12 +6,14 @@ namespace Masa.Contrib.Authentication.Oidc.EntityFrameworkCore.Repositories; public class ClientRepository : IClientRepository { IClientCache _cache; - OidcDbContext _context; + DbContext _context; + IRepository _repository; - public ClientRepository(IClientCache cache, OidcDbContext context) + public ClientRepository(IClientCache cache, OidcDbContext context, IRepository repository) { _cache = cache; _context = context; + _repository = repository; } public async Task> GetPaginatedListAsync(int page, int pageSize, Expression>? condition = null) @@ -65,25 +67,25 @@ public async Task GetCountAsync(Expression> predicate) public async ValueTask AddAsync(Client client) { - var newClient = await _context.AddAsync(client); + var newClient = await _repository.AddAsync(client); await _context.SaveChangesAsync(); var detail = await GetDetailAsync(client.Id); await _cache.SetAsync(detail!); - return newClient.Entity; + return newClient; } public async Task UpdateAsync(Client client) { - var newClient = _context.Update(client); + var newClient = await _repository.UpdateAsync(client); await _context.SaveChangesAsync(); var detail = await GetDetailAsync(client.Id); await _cache.SetAsync(detail!); - return newClient.Entity; + return newClient; } public async Task RemoveAsync(Client client) { - _context.Remove(client); + await _repository.RemoveAsync(client); await _context.SaveChangesAsync(); await _cache.RemoveAsync(client); } diff --git a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/IdentityResourceRepository.cs b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/IdentityResourceRepository.cs index eba523d3d..48621f5d0 100644 --- a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/IdentityResourceRepository.cs +++ b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/IdentityResourceRepository.cs @@ -6,12 +6,14 @@ namespace Masa.Contrib.Authentication.Oidc.EntityFrameworkCore.Repositories; public class IdentityResourceRepository : IIdentityResourceRepository { SyncCache _cache; - OidcDbContext _context; + DbContext _context; + IRepository _repository; - public IdentityResourceRepository(SyncCache cache, OidcDbContext context) + public IdentityResourceRepository(SyncCache cache, OidcDbContext context, IRepository repository) { _cache = cache; _context = context; + _repository = repository; } public async Task> GetPaginatedListAsync(int page, int pageSize, Expression>? condition = null) @@ -62,24 +64,24 @@ public async ValueTask AddAsync(IdentityResource identityResou if (exist) throw new UserFriendlyException($"IdentityResource with name {identityResource.Name} already exists"); - var newIdentityResource = await _context.AddAsync(identityResource); + var newIdentityResource = await _repository.AddAsync(identityResource); await _context.SaveChangesAsync(); await _cache.SyncIdentityResourceCacheAsync(identityResource.Id); - return newIdentityResource.Entity; + return newIdentityResource; } public async Task UpdateAsync(IdentityResource identityResource) { - var newIdentityResource = _context.Update(identityResource); + var newIdentityResource = await _repository.UpdateAsync(identityResource); await _context.SaveChangesAsync(); await _cache.SyncIdentityResourceCacheAsync(identityResource.Id); - return newIdentityResource.Entity; + return newIdentityResource; } public async Task RemoveAsync(IdentityResource identityResource) { - _context.Remove(identityResource); + await _repository.RemoveAsync(identityResource); await _context.SaveChangesAsync(); await _cache.RemoveIdentityResourceCacheAsync(identityResource); } @@ -96,13 +98,13 @@ public async Task AddStandardIdentityResourcesAsync() { existData.Update(identityResource.DisplayName, identityResource.Description ?? "", true, identityResource.Required, identityResource.Emphasize, identityResource.ShowInDiscoveryDocument, true); existData.BindUserClaims(userClaimIds); - _context.Update(existData); + await _repository.UpdateAsync(existData); } else { existData = new IdentityResource(identityResource.Name, identityResource.DisplayName, identityResource.Description ?? "", true, identityResource.Required, identityResource.Enabled, identityResource.ShowInDiscoveryDocument, true); existData.BindUserClaims(userClaimIds); - await _context.AddAsync(existData); + await _repository.AddAsync(existData); } syncIdentityResources.Add(existData); } diff --git a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/UserClaimRepository.cs b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/UserClaimRepository.cs index 545f0af8c..f49a2548e 100644 --- a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/UserClaimRepository.cs +++ b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/Repositories/UserClaimRepository.cs @@ -5,10 +5,12 @@ namespace Masa.Contrib.Authentication.Oidc.EntityFrameworkCore.Repositories; public class UserClaimRepository : IUserClaimRepository { - OidcDbContext _context; + IRepository _repository; + DbContext _context; - public UserClaimRepository(OidcDbContext context) + public UserClaimRepository(IRepository repository, OidcDbContext context) { + _repository = repository; _context = context; } @@ -59,22 +61,17 @@ public async ValueTask AddAsync(UserClaim userClaim) if (exist) throw new UserFriendlyException($"UserClaim with name {userClaim.Name} already exists"); - var newUserClaim = await _context.AddAsync(userClaim); - await _context.SaveChangesAsync(); - return newUserClaim.Entity; + return await _repository.AddAsync(userClaim); } public async Task UpdateAsync(UserClaim userClaim) { - var newUserClaim = _context.Update(userClaim); - await _context.SaveChangesAsync(); - return newUserClaim.Entity; + return await _repository.UpdateAsync(userClaim); } public async Task RemoveAsync(UserClaim userClaim) { - _context.Remove(userClaim); - await _context.SaveChangesAsync(); + await _repository.RemoveAsync(userClaim); } public async Task AddStandardUserClaimsAsync() @@ -87,6 +84,6 @@ public async Task AddStandardUserClaimsAsync() userClaims.Add(new UserClaim(claim.Key, claim.Value)); } - await _context.AddRangeAsync(userClaims); + await _repository.AddRangeAsync(userClaims); } } diff --git a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/ServiceCollectionExtensions.cs b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/ServiceCollectionExtensions.cs index 282ba1423..e45376674 100644 --- a/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/ServiceCollectionExtensions.cs +++ b/src/Authentication/Masa.Contrib.Authentication.Oidc.EntityFrameworkCore/ServiceCollectionExtensions.cs @@ -5,9 +5,9 @@ namespace Masa.Contrib.Authentication.Oidc.EntityFrameworkCore; public static class ServiceCollectionExtensions { - public static IServiceCollection AddOidcDbContext(this IServiceCollection services, Action optionsAction) + public static IServiceCollection AddOidcDbContext(this IServiceCollection services) where T : DbContext { - services.AddDbContext(optionsAction); + services.AddScoped(provider => new OidcDbContext(provider.GetRequiredService())); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/src/BasicAbility/Masa.Contrib.BasicAbility.Auth/ServiceCollectionExtensions.cs b/src/BasicAbility/Masa.Contrib.BasicAbility.Auth/ServiceCollectionExtensions.cs index 96d36313f..03c910b79 100644 --- a/src/BasicAbility/Masa.Contrib.BasicAbility.Auth/ServiceCollectionExtensions.cs +++ b/src/BasicAbility/Masa.Contrib.BasicAbility.Auth/ServiceCollectionExtensions.cs @@ -8,7 +8,7 @@ public static class ServiceCollectionExtensions public static IServiceCollection AddAuthClient(this IServiceCollection services, string authServiceBaseAddress) { ArgumentNullException.ThrowIfNull(authServiceBaseAddress, nameof(authServiceBaseAddress)); -#warning modify + services.AddSingleton(); return services.AddAuthClient(callerOptions => { diff --git a/src/BuildingBlocks/MASA.BuildingBlocks b/src/BuildingBlocks/MASA.BuildingBlocks index c19f0f87f..63dca8be6 160000 --- a/src/BuildingBlocks/MASA.BuildingBlocks +++ b/src/BuildingBlocks/MASA.BuildingBlocks @@ -1 +1 @@ -Subproject commit c19f0f87fb185a12bae9b238f82d68c4f91cdb02 +Subproject commit 63dca8be684c9fadcf21bc6529b2f9dfb7699c22