Pibd-22_Lyakhov_T.I._Simple/StudentProgressRecord/Program.cs
2024-11-18 14:55:50 +04:00

65 lines
2.2 KiB
C#

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Serilog;
using StudentProgressRecord.Forms;
using StudentProgressRecord.IRepositories;
using StudentProgressRecord.Repositories;
using StudentProgressRecord.RepositoryImp;
using Unity;
using Unity.Lifetime;
using Unity.Microsoft.Logging;
namespace StudentProgressRecord
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
Application.Run(CreateContainer().Resolve<FormUniversity>());
}
private static IUnityContainer CreateContainer()
{
var container = new UnityContainer();
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
container.RegisterType<IConnectionString,ConnectionString>(new SingletonLifetimeManager());
container.RegisterType<IStatementRepository, StatementRepository>
(new TransientLifetimeManager());
container.RegisterType<IStudentRepository, StudentRepository>
(new TransientLifetimeManager());
container.RegisterType<ISubjectRepository, SubjectRepository>
(new TransientLifetimeManager());
container.RegisterType<ITeacherRepository, TeacherRepository>
(new TransientLifetimeManager());
container.RegisterType<IStudentTransitionRepository, StudentTransitionRepository>
(new TransientLifetimeManager());
return container;
}
private static LoggerFactory CreateLoggerFactory()
{
var lf = new LoggerFactory();
lf.AddSerilog(new LoggerConfiguration()
.ReadFrom.Configuration(new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsetting.json")
.Build())
.CreateLogger());
return lf;
}
}
}