[feature] 添加Redis 相关服务 未应用到python
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using SiteManagementSystem_SoftwareEngineering_.Configuration;
|
||||
using SiteManagementSystem_SoftwareEngineering_.Factory;
|
||||
using SiteManagementSystem_SoftwareEngineering_.Interface;
|
||||
using SiteManagementSystem_SoftwareEngineering_.Model;
|
||||
using SiteManagementSystem_SoftwareEngineering_.Service;
|
||||
using static SiteManagementSystem_SoftwareEngineering_.Service.UserManagerService;
|
||||
|
||||
@@ -24,18 +25,38 @@ namespace SiteManagementSystem_SoftwareEngineering_.Extension
|
||||
services.AddScoped<ITokenFactory, TokenFactory>(_ => new TokenFactory(config));
|
||||
return services;
|
||||
}
|
||||
public static IServiceCollection AddUserManager(this IServiceCollection services, Action<SecretConfig> options)
|
||||
|
||||
public static IServiceCollection AddUserManager(
|
||||
this IServiceCollection services,
|
||||
Action<SecretConfig> options
|
||||
)
|
||||
{
|
||||
var config = new SecretConfig();
|
||||
options(config);
|
||||
if (config.HashSalt is null) throw new ArgumentNullException(nameof(config.HashSalt) + "can not be null");
|
||||
if (config.HashSalt is null)
|
||||
throw new ArgumentNullException(nameof(config.HashSalt) + "can not be null");
|
||||
services.AddScoped<IUserManageService, UserManageService>(services =>
|
||||
{
|
||||
var logger = services.GetRequiredService<ILogger<UserManageService>>();
|
||||
var storageService= services.GetRequiredService<SQLService>();
|
||||
var storageService = services.GetRequiredService<SQLService>();
|
||||
return new UserManageService(storageService, logger, config.HashSalt);
|
||||
});
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddRedisUtils(
|
||||
this IServiceCollection services,
|
||||
Action<RedisConfig> options
|
||||
)
|
||||
{
|
||||
var config = new RedisConfig();
|
||||
options(config);
|
||||
if (config.RedisConnectionString is null)
|
||||
throw new ArgumentNullException("Redis ConnectionString is null.");
|
||||
services.AddSingleton<RedisUtils>(services =>
|
||||
new RedisUtils(config.RedisConnectionString, config.RedisDB, services.GetRequiredService<ILogger<RedisUtils>>())
|
||||
);
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user