Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
non Generic Host sample
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
public class Program
public static void Main(string[] args)
//setup our DI
var serviceProvider = new ServiceCollection()
.AddSingleton<IFooService, FooService>()
.AddSingleton<IBarService, BarService>()
//configure console logging
var logger = serviceProvider.GetService<ILoggerFactory>().CreateLogger<Program>();
logger.LogDebug("Starting application");
//do the actual work here
var bar = serviceProvider.GetService<IBarService>();
logger.LogDebug("All done!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.