.NET 6 – Inject service into program.cs

Using .Net 6 is easy. Just execute GetService method after configure app services and have ran Build method.

WebApplication? app = builder.Build();

var someService = app.Services.GetService<ISomeService>();

someService.DoSomething();

Leave a Comment