using System.Reflection; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using StandManager.Domain.DTO; using StandManager.Infrastructure.DAL.Context; using StandManager.MailProcessor.Mail; using StandManager.Service; using StandManager.Service.Interfaces; using StandManager.Service.Repository; var host = Host.CreateDefaultBuilder(args) .ConfigureServices((context, services) => { //DI var types = Assembly.Load("StandManager.Service").GetTypes(); var allProviderTypes = types.Where(t => t.Namespace != null && (t.FullName?.EndsWith("Service") ?? false)).ToList(); foreach (var intfc in allProviderTypes.Where(t => t.IsInterface)) { var impl = allProviderTypes.FirstOrDefault(c => c.IsClass && intfc.Name[1..] == c.Name); if (impl != null) services.AddScoped(intfc, impl); } var emailConfigSection = context.Configuration.GetSection("EmailConfig"); services.Configure(emailConfigSection); //Database var connectionString = context.Configuration.GetConnectionString("ConnectionString"); services.AddDbContext(options => options.UseSqlServer(connectionString) ); services.AddScoped(typeof(IStandManagerGenericRepository<>), typeof(StandManagerGenericRepository<>)); services.AddScoped(); services.AddScoped(); services.AddScoped(); }) .Build(); using var scope = host.Services.CreateScope(); var processor = scope.ServiceProvider.GetRequiredService(); processor.Process();