private static void EarlyBindingExample() { IMessageWriter writer = new SecureMessageWriter( writer: new ConsoleMessageWriter(), identity: GetIdentity()); var salutation = new Salutation(writer); salutation.Exclaim(); }
private static void LateBindingExample() { IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); string typeName = configuration["messageWriter"]; Type type = Type.GetType(typeName, throwOnError: true); IMessageWriter writer = new SecureMessageWriter( writer: (IMessageWriter)Activator.CreateInstance(type), identity: GetIdentity()); var salutation = new Salutation(writer); salutation.Exclaim(); }