Added service level caching to IdentityService, Communication and Evidence
This commit is contained in:
@@ -1,19 +1,28 @@
|
||||
using Microsoft.Extensions.Caching.Hybrid;
|
||||
using PostFundManagement.Application.Abstractions;
|
||||
using PostFundManagement.Application.Abstractions;
|
||||
using PostFundManagement.Application.Abstractions.Services;
|
||||
using PostFundManagement.Application.Services.Communications;
|
||||
using PostFundManagement.Application.Services.Evidence;
|
||||
using PostFundManagement.Application.Services.Shared;
|
||||
using PostFundManagement.Application.Services.Users;
|
||||
using PostFundManagement.Domain.Abstractions;
|
||||
|
||||
namespace PostFundManagement.Application.Extensions;
|
||||
|
||||
public static class General
|
||||
{
|
||||
public static IServiceCollection AddRegisterServices(this IServiceCollection services, IConfiguration configuration)
|
||||
public static IServiceCollection AddRegisterServicesWithCaching(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var serviceType = typeof(IService);
|
||||
services.AddScoped<ICommunicationsService, CommunicationsService>();
|
||||
services.Decorate<ICommunicationsService, CommunicationsCacheService>();
|
||||
|
||||
var sharedImplementations = typeof(IApplication).Assembly.GetTypes()
|
||||
.Where(t => serviceType.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract);
|
||||
services.AddScoped<IEvidenceService, EvidenceService>();
|
||||
services.Decorate<IEvidenceService, EvidenceCacheService>();
|
||||
|
||||
foreach (var sharedImplementation in sharedImplementations) services.AddScoped(sharedImplementation);
|
||||
services.AddScoped<IUserService, UserService>();
|
||||
services.Decorate<IUserService, UserCacheService>();
|
||||
|
||||
services.AddScoped<IIdentityService, IdentityService>();
|
||||
services.Decorate<IIdentityService, IdentityCacheService>();
|
||||
|
||||
services.AddStackExchangeRedisCache(options =>
|
||||
options.Configuration = configuration.GetConnectionString("Redis"));
|
||||
@@ -27,6 +36,18 @@ public static class General
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddSharedServices(this IServiceCollection services)
|
||||
{
|
||||
var serviceType = typeof(IService);
|
||||
|
||||
var sharedImplementations = typeof(IApplication).Assembly.GetTypes()
|
||||
.Where(t => serviceType.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract);
|
||||
|
||||
foreach (var sharedImplementation in sharedImplementations) services.AddScoped(sharedImplementation);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static Guid GetUserId(this HttpContext context) => (Guid)context.Items[Domain.Extensions.Constants.UserIdItemKey]!;
|
||||
|
||||
public static string GetUserEmail(this HttpContext context) => (string)context.Items[Domain.Extensions.Constants.EmailtemKey]!;
|
||||
|
||||
Reference in New Issue
Block a user