| | | 1 | | using Syki.Back.Emails; |
| | | 2 | | using Syki.Back.Storage; |
| | | 3 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 4 | | |
| | | 5 | | namespace Syki.Back.Configs; |
| | | 6 | | |
| | | 7 | | public static class ServicesConfigs |
| | | 8 | | { |
| | | 9 | | public static void AddServicesConfigs(this WebApplicationBuilder builder) |
| | | 10 | | { |
| | 2 | 11 | | builder.Services.AddServices(typeof(ISykiService)); |
| | | 12 | | |
| | 2 | 13 | | builder.Services.AddScoped<IEmailsService, EmailsService>(); |
| | 2 | 14 | | builder.Services.AddScoped<IStorageService, FakeStorageService>(); |
| | | 15 | | |
| | 2 | 16 | | if (EnvironmentExtensions.IsDevelopmentOrTesting()) |
| | | 17 | | { |
| | 2 | 18 | | builder.Services.Replace(ServiceDescriptor.Singleton<IEmailsService, FakeEmailsService>()); |
| | | 19 | | } |
| | 2 | 20 | | } |
| | | 21 | | |
| | | 22 | | private static void AddServices(this IServiceCollection services, Type marker) |
| | | 23 | | { |
| | 2 | 24 | | var types = AppDomain.CurrentDomain.GetAssemblies() |
| | 322 | 25 | | .Where(s => s.FullName.StartsWith("Back")) |
| | 2 | 26 | | .SelectMany(s => s.GetTypes()) |
| | 2148 | 27 | | .Where(p => marker.IsAssignableFrom(p) && !p.IsInterface) |
| | 2 | 28 | | .ToList(); |
| | | 29 | | |
| | 148 | 30 | | foreach (var type in types) |
| | | 31 | | { |
| | 72 | 32 | | services.AddScoped(type); |
| | | 33 | | } |
| | 2 | 34 | | } |
| | | 35 | | } |