66 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Core.Blueprint.Mongo;
 | |
| using Core.Thalos.Adapters;
 | |
| using Core.Thalos.Infraestructure.Caching.Contracts;
 | |
| using Core.Thalos.Infraestructure.Contexts.Mongo;
 | |
| using Core.Thalos.Provider.Contracts;
 | |
| using Core.Thalos.Provider.Providers;
 | |
| using Core.Thalos.Provider.Providers.Onboarding;
 | |
| using LSA.Core.Dapper.Service.Caching;
 | |
| using Microsoft.Extensions.Configuration;
 | |
| using Microsoft.Extensions.DependencyInjection;
 | |
| using Microsoft.Extensions.Logging;
 | |
| using Microsoft.Extensions.Options;
 | |
| using MongoDB.Driver;
 | |
| 
 | |
| namespace Core.Thalos.Provider
 | |
| {
 | |
|     public static class ServiceCollectionExtensions
 | |
|     {
 | |
|         public static IServiceCollection AddDALLayerServices(this IServiceCollection services, IConfiguration configuration)
 | |
|         {
 | |
|             //Mongo
 | |
|             services.AddScoped<IModuleProvider, ModuleProvider>();
 | |
|             services.AddScoped<CollectionRepository<ModuleAdapter>>();
 | |
| 
 | |
|             services.AddScoped<IPermissionProvider, PermissionProvider>();
 | |
|             services.AddScoped<CollectionRepository<PermissionAdapter>>();
 | |
| 
 | |
|             services.AddScoped<IRoleProvider, RoleProvider>();
 | |
|             services.AddScoped<CollectionRepository<RoleAdapter>>();
 | |
| 
 | |
|             services.AddScoped<IUserProvider, UserProvider>();
 | |
|             services.AddScoped<CollectionRepository<UserAdapter>>();
 | |
| 
 | |
|             return services;
 | |
|         }
 | |
| 
 | |
|         private static IServiceCollection AddLogs(this IServiceCollection services)
 | |
|         {
 | |
|             services.AddLogging();
 | |
|             var serviceProvider = services.BuildServiceProvider();
 | |
|             //var logger = serviceProvider.GetService<ILogger<DashboardDALService>>(); //Add for Markup class later TODO
 | |
| 
 | |
|             //services.AddSingleton(typeof(ILogger), logger);
 | |
| 
 | |
|             return services;
 | |
|         }
 | |
| 
 | |
|         private static IServiceCollection AddRedisCacheService(this IServiceCollection services, IConfiguration configuration)
 | |
|         {
 | |
|             var source = configuration.GetSection("ConnectionStrings");
 | |
| 
 | |
|             var redisConnectionString = source["Redis"]?.ToString();
 | |
| 
 | |
|             if (string.IsNullOrEmpty(redisConnectionString))
 | |
|             {
 | |
|                 throw new InvalidOperationException("Redis connection string is not configured.");
 | |
|             }
 | |
| 
 | |
|             services.AddSingleton<ICacheService>(provider =>
 | |
|                 new CacheService(redisConnectionString, provider.GetRequiredService<ILogger<CacheService>>()));
 | |
| 
 | |
|             return services;
 | |
|         }
 | |
|     }
 | |
| }
 | 
