Created
January 21, 2019 04:41
-
-
Save guitarrapc/426753ed981708d7211301be67e3f09c to your computer and use it in GitHub Desktop.
non Generic Host sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Logging; | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
//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