74 lines
3.0 KiB
C#
74 lines
3.0 KiB
C#
using PostFundManagement.Application.Abstractions;
|
|
using PostFundManagement.Application.Abstractions.Services;
|
|
using PostFundManagement.Application.Services.Communications;
|
|
using PostFundManagement.Application.Services.Evidence;
|
|
using PostFundManagement.Application.Services.Execution;
|
|
using PostFundManagement.Application.Services.Governance;
|
|
using PostFundManagement.Application.Services.Grants;
|
|
using PostFundManagement.Application.Services.Projects;
|
|
using PostFundManagement.Application.Services.Shared;
|
|
using PostFundManagement.Application.Services.Tools;
|
|
using PostFundManagement.Application.Services.Users;
|
|
using PostFundManagement.Domain.Abstractions;
|
|
|
|
namespace PostFundManagement.Application.Extensions;
|
|
|
|
public static class Services
|
|
{
|
|
public static IServiceCollection AddRegisterServicesWithCaching(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
services.AddScoped<ICommunicationsService, CommunicationsService>();
|
|
services.Decorate<ICommunicationsService, CommunicationsCacheService>();
|
|
|
|
services.AddScoped<IEvidenceService, EvidenceService>();
|
|
services.Decorate<IEvidenceService, EvidenceCacheService>();
|
|
|
|
services.AddScoped<IUserService, UserService>();
|
|
services.Decorate<IUserService, UserCacheService>();
|
|
|
|
services.AddScoped<IIdentityService, IdentityService>();
|
|
services.Decorate<IIdentityService, IdentityCacheService>();
|
|
|
|
services.AddScoped<IExecutionService, ExecutionService>();
|
|
services.Decorate<IExecutionService, ExecutionCacheService>();
|
|
|
|
services.AddScoped<IGovernanceService, GovernanceService>();
|
|
services.Decorate<IGovernanceService, GovernanceCacheService>();
|
|
|
|
services.AddScoped<IGrantsService, GrantsService>();
|
|
services.Decorate<IGrantsService, GrantsCacheService>();
|
|
|
|
services.AddScoped<IProjectService, ProjectService>();
|
|
services.Decorate<IProjectService, ProjectCacheService>();
|
|
|
|
services.AddScoped<IToolService, ToolService>();
|
|
services.Decorate<IToolService, ToolCacheService>();
|
|
|
|
services.AddStackExchangeRedisCache(options =>
|
|
{
|
|
options.Configuration = configuration.GetConnectionString("Redis");
|
|
options.InstanceName = "PFM-API_";
|
|
});
|
|
|
|
services.AddHybridCache(options => options.DefaultEntryOptions = new HybridCacheEntryOptions
|
|
{
|
|
Expiration = TimeSpan.FromMinutes(2),
|
|
LocalCacheExpiration = TimeSpan.FromMinutes(30)
|
|
});
|
|
|
|
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;
|
|
}
|
|
}
|