46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using OFBButte.Application.Configuration;
|
|
using OFBButte.Application.Database;
|
|
using OFBButte.Application.Email;
|
|
using OFBButte.Database;
|
|
using OFBButte.Infrastructure.Email;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace OFBButte.Console
|
|
{
|
|
class Program
|
|
{
|
|
|
|
static ServiceProvider services;
|
|
|
|
static async Task Main(string[] args)
|
|
{
|
|
SetupDI();
|
|
|
|
await services.GetService<App>().Run();
|
|
}
|
|
|
|
static void SetupDI()
|
|
{
|
|
var builder = new ConfigurationBuilder();
|
|
builder.AddJsonFile("appsettings.json", false, true);
|
|
builder.AddJsonFile("appsettings.Development.json", true, true);
|
|
var config = builder.Build();
|
|
|
|
|
|
var serviceCollection = new ServiceCollection();
|
|
serviceCollection.Configure<AppSettings>(a => config.GetSection("app").Bind(a));
|
|
|
|
serviceCollection.AddSingleton<IEmailSender>(new EmailSender());
|
|
serviceCollection.AddDbContext<OFBContext>(o => OFBContext.UseMySql(o, config.GetConnectionString("OFBContext")));
|
|
serviceCollection.AddScoped<IOFBContext, OFBContext>(s => s.GetService<OFBContext>());
|
|
serviceCollection.AddTransient<App>();
|
|
services = serviceCollection.BuildServiceProvider();
|
|
}
|
|
|
|
|
|
}
|
|
}
|