How can I use Microsoft.Extensions.DependencyInjection in an .NET Core console app?
I use it basically like so:
Install nuget Microsoft.Extensions.DependencyInjection
Then in Program.cs
using Microsoft.Extensions.DependencyInjection;
public class Program
{
public static void Main(string[] args)
{
var services = new ServiceCollection()
.AddSingleton<WhateverType>(new WhateverType());
var serviceProvider = services.BuildServiceProvider();
serviceProvider.GetService<WhateverType>().DoWork();
}
}