예제 #1
0
        static void Main()
        {
            IMessageWriter writer     = new ConsoleMessageWriter();
            var            salutation = new Salutation(writer);

            salutation.Exclaim();
        }
예제 #2
0
 public void exclaim_will_write_correct_message_to_message_writer()
 {
     var mock = new Mock<IMessageWriter>();
     var salutation = new Salutation(mock.Object);
     salutation.Exclaim();
     mock.Verify(w=>w.Write("Hello, DI!"));
 }
예제 #3
0
        static void Main(string[] args)
        {
            //IMessageWriter writer = new ConsoleMessageWriter();
            IMessageWriter writer     = ConfigurationBuilder.GetMessageWriter();
            var            salutation = new Salutation(writer);

            salutation.Exclaim();
        }
예제 #4
0
        public void ExclaimWillWriteCorrectMessageToMessageWriter()
        {
            var writerMock = new Mock <IMessageWriter>();
            var sut        = new Salutation(writerMock.Object);

            sut.Exclaim();
            writerMock.Verify(w => w.Write("Hello DI!"));
        }
예제 #5
0
        static void Main(string[] args)
        {
            //IMessageWriter writer = new ConsoleMessageWriter();
            IMessageWriter writer     = new SecureMessageWriter(new ConsoleMessageWriter());
            var            salutation = new Salutation(writer);

            salutation.Exclaim();
        }
예제 #6
0
        static void Main(string[] args)
        {
            IMessageWriter writer     = new ConsoleMessageWriter();
            var            salutation = new Salutation(writer);

            salutation.Exclaim();
            Console.ReadKey();
        }
예제 #7
0
        public void ExclaimWillWriteCorrectMesageToMessageWriter()
        {
            var writer = new SpyMessage();
            var sut    = new Salutation(writer);

            sut.Exclaim();
            Assert.AreEqual(
                expected: "Hello DI!",
                actual: writer.WrittenMessage);
        }
예제 #8
0
        static void Main(string[] args)
        {
            IMessageWriter writer     = new ConsoleMessageWriter();
            var            salutation = new Salutation(writer);

            salutation.Exclaim();

            var writer1     = new ConsoleMessageWriterPlus();
            var salutation1 = new Salutation(writer1);

            salutation1.Exclaim();
        }
예제 #9
0
        static void Main(string[] args)
        {
            var typeName = ConfigurationManager.AppSettings["messageWriter"];
            var type     = Type.GetType(typeName, true);

            //IMessageWriter writer = (IMessageWriter)Activator.CreateInstance(type);
            IMessageWriter writer = new SecureMessageWriter(new ConsoleMessageWriter());

            var salutation = new Salutation(writer);

            salutation.Exclaim();
        }
예제 #10
0
파일: Program.cs 프로젝트: qszhuan/Learn-DI
        static void Main(string[] args)
        {
            //create writer using config file
            //            var writer = MessageWriter();

              //  var writer = SecureMessageWriter();

            var writer = AutofacWriter();

            var salutation = new Salutation(writer);

            salutation.Exclaim();
        }
예제 #11
0
        static void Main(string[] args)
        {
            // Original DI Example
            IMessageWriter writer     = new ConsoleMessageWriter();
            var            salutation = new Salutation(writer);

            salutation.Exclaim();

            // Late Binding Example
            var            typeName          = ConfigurationManager.AppSettings["messageWriter"];
            var            type              = Type.GetType(typeName, true);
            IMessageWriter lateBindingWriter = (IMessageWriter)Activator.CreateInstance(type);

            lateBindingWriter.Write("HelloDI via Late Binding");

            // Extensibility Example
            IMessageWriter secureMessageWriter = new SecureMessageWriter(new ConsoleMessageWriter());

            secureMessageWriter.Write("HelloDI via Extensibility");

            Console.ReadLine();

            Trace.WriteLine("Force Git to update");
        }