Skip to content

Instantly share code, notes, and snippets.

@teamday
Created August 17, 2018 07:11
Show Gist options
  • Save teamday/a7ab05f145c9430b551da31e7d9f4c34 to your computer and use it in GitHub Desktop.
Save teamday/a7ab05f145c9430b551da31e7d9f4c34 to your computer and use it in GitHub Desktop.
//setup our DI
var serviceProvider = new ServiceCollection()
.AddLogging()
.AddSingleton<IFooService, FooService>()
.AddSingleton<IBarService, BarService>()
.BuildServiceProvider();
//configure console logging
serviceProvider
.GetService<ILoggerFactory>()
.AddConsole(LogLevel.Debug);
var logger = serviceProvider.GetService<ILoggerFactory>()
.CreateLogger<Program>();
logger.LogDebug("Starting application");
//do the actual work here
var bar = serviceProvider.GetService<IBarService>();
bar.DoSomeRealWork();
logger.LogDebug("All done!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment