예제 #1
0
        private static void EarlyBindingExample()
        {
            IMessageWriter writer =
                new SecureMessageWriter(
                    writer: new ConsoleMessageWriter(),
                    identity: GetIdentity());

            var salutation = new Salutation(writer);

            salutation.Exclaim();
        }
예제 #2
0
        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();
        }