Example for Dependency Injection in Console App (like Startup in .Net Core)
Introduction:
- Install Microsoft.Extensions.Hosting package in NuGet
CreateHostBuilder
function is pretending Startup function in ASP.NET Core - we put there all dependencies- Lines
var host = CreateHostBuilder(args).Build(); host.Services.GetRequiredService<Program>().Run();
are configuration for our dependency injection