DI Setup using HostApplicationBuilder
This commit is contained in:
@@ -1,21 +1,22 @@
|
||||
using EF_Demo;
|
||||
using EF_Demo;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
Console.OutputEncoding = System.Text.Encoding.UTF8;
|
||||
|
||||
using ServiceProvider serviceProvider = DISetup.BuildDI();
|
||||
using var host = DISetup.BuildHost(args);
|
||||
Demo demo = host.Services.GetRequiredService<Demo>();
|
||||
|
||||
Demo.PrintPeople(serviceProvider, 1976);
|
||||
demo.PrintPeople(1976);
|
||||
Util.EnterToContinue();
|
||||
|
||||
int? eventId = Demo.AddEvent(serviceProvider, "Spring festival", new DateOnly(2026, 4, 30));
|
||||
int? eventId = demo.AddEvent("Spring festival", new DateOnly(2026, 4, 30));
|
||||
Util.EnterToContinue();
|
||||
|
||||
if (eventId.HasValue)
|
||||
{
|
||||
Demo.PostponeEvent(serviceProvider, eventId.Value, days: 5);
|
||||
demo.PostponeEvent(eventId.Value, days: 5);
|
||||
Util.EnterToContinue();
|
||||
|
||||
Demo.DeleteEvent(serviceProvider, eventId.Value);
|
||||
demo.DeleteEvent(eventId.Value);
|
||||
Util.EnterToContinue(clearConsole: false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user