PIbd-21_Tarasov_V.D._Optika/ProjectOptika/Scripts/Program.cs

53 lines
1.9 KiB
C#

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using ProjectOptika.Scripts.Repositories;
using ProjectOptika.Scripts.Repositories.Implementations;
using Serilog;
using Unity;
using Unity.Microsoft.Logging;
namespace ProjectOptika.Scripts
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(CreateContainer().Resolve<FormOptika>());
}
private static UnityContainer CreateContainer () {
var container = new UnityContainer();
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
container.RegisterType<IAccessoriesRepository, AccessoriesRepository>();
container.RegisterType<IClientRepositiory, ClientRepositiory>();
container.RegisterType<IEmployeeRepository, EmployeeRepository>();
container.RegisterType<ISpecificationsRepository, SpecificationsRepository>();
container.RegisterType<IOrderRepository, OrderRepository>();
container.RegisterType<IConnectionString, ConnectionString>();
return container;
}
private static LoggerFactory CreateLoggerFactory()
{
var loggerFactory = new LoggerFactory();
loggerFactory.AddSerilog(new LoggerConfiguration()
.ReadFrom.Configuration(new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build())
.CreateLogger());
return loggerFactory;
}
}
}