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