47 lines
2.0 KiB
C#
47 lines
2.0 KiB
C#
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.Service;
|
|
using StandManager.Service.Interfaces;
|
|
using StandManager.Service.Repository;
|
|
using StandManager.Service.Resolver;
|
|
|
|
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<EmailConfig>(emailConfigSection);
|
|
|
|
//Database
|
|
var connectionString = context.Configuration.GetConnectionString("ConnectionString");
|
|
services.AddDbContext<StandManagerDbContext>(options =>
|
|
options.UseSqlServer(connectionString)
|
|
);
|
|
|
|
services.AddScoped(typeof(IStandManagerGenericRepository<>), typeof(StandManagerGenericRepository<>));
|
|
services.AddScoped<IStandManagerUnitOfWork, StandManagerUnitOfWork>();
|
|
services.AddScoped<IManagerService, ManagerService>();
|
|
|
|
services.AddScoped<MailProcessor>();
|
|
//MailProcessor
|
|
services.AddScoped<IMailProcessor, RegistrazioneMailProcessor>();
|
|
services.AddScoped<IMailProcessorResolver, MailProcessorResolver>();
|
|
})
|
|
.Build();
|
|
|
|
using var scope = host.Services.CreateScope();
|
|
var processor = scope.ServiceProvider.GetRequiredService<MailProcessor>();
|
|
processor.Process(); |