Created
April 4, 2020 19:27
-
-
Save arnabdas/5bfec1419d66aca4217e182e6c10313a to your computer and use it in GitHub Desktop.
Using Appsettings In Console Applications - Taken from Seeman
This file contains hidden or 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
{ | |
"messageWriter": | |
"Ploeh.Samples.HelloDI.Console.ConsoleMessageWriter, HelloDI.Console" | |
} |
This file contains hidden or 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
IConfigurationRoot configuration = new ConfigurationBuilder() | |
.SetBasePath(Directory.GetCurrentDirectory()) | |
.AddJsonFile("appsettings.json") | |
.Build(); | |
string typeName = configuration["messageWriter"]; | |
Type type = Type.GetType(typeName, throwOnError: true); | |
IMessageWriter writer = (IMessageWriter)Activator.CreateInstance(type); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment