| | 1 | | using Syki.Back.Storage; |
| | 2 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | 3 | |
|
| | 4 | | namespace Syki.Back.Configs; |
| | 5 | |
|
| | 6 | | public static class ServicesConfigs |
| | 7 | | { |
| | 8 | | public static void AddServicesConfigs(this WebApplicationBuilder builder) |
| | 9 | | { |
| 4 | 10 | | builder.Services.AddServices(typeof(IAdmService)); |
| 4 | 11 | | builder.Services.AddServices(typeof(ICrossService)); |
| 4 | 12 | | builder.Services.AddServices(typeof(IStudentService)); |
| 4 | 13 | | builder.Services.AddServices(typeof(ITeacherService)); |
| 4 | 14 | | builder.Services.AddServices(typeof(IAcademicService)); |
| | 15 | |
|
| 4 | 16 | | builder.Services.AddScoped<IStorageService, AzureBlobStorageService>(); |
| | 17 | |
|
| 4 | 18 | | if (Env.IsDevelopment() || Env.IsTesting()) |
| | 19 | | { |
| 4 | 20 | | builder.Services.Replace(ServiceDescriptor.Singleton<IStorageService, FakeStorageService>()); |
| | 21 | | } |
| 4 | 22 | | } |
| | 23 | |
|
| | 24 | | private static void AddServices(this IServiceCollection services, Type marker) |
| | 25 | | { |
| 20 | 26 | | var types = AppDomain.CurrentDomain.GetAssemblies() |
| 3734 | 27 | | .Where(s => s.FullName.StartsWith("Back")) |
| 20 | 28 | | .SelectMany(s => s.GetTypes()) |
| 27280 | 29 | | .Where(p => marker.IsAssignableFrom(p) && !p.IsInterface) |
| 20 | 30 | | .ToList(); |
| | 31 | |
|
| 880 | 32 | | foreach (var type in types) |
| | 33 | | { |
| 420 | 34 | | services.AddScoped(type); |
| | 35 | | } |
| 20 | 36 | | } |
| | 37 | | } |