Exemplo n.º 1
0
        private static void TestBridgeDecoratorAndProxy()
        {
            var officeAddress = EmailAddressFactory.GetOfficeAddress();

            //Elore tudom h hidat akarok hasznalni
            //Levalasztom a konkret megvalositast a hasznalattol, ez az adatok tarolasanal a repository minta
            //E helyett hasznalhatunk ninject dependency injection-t
            // var repo = new PersonRepository();
            //Ninject megoldas:
            var repo = kernel.Get <IPersonRepository>();

            var person   = repo.GetBirthdayPeople();
            var sendWith = AbstractSendWith.Factory <SendWith>();
            var service  = new EmailService(sendWith);

            //Decorator minta
            var serviceWithLogger = new EmailServiceWithLogger(service, sendWith);
            //EmailService serviceWithLogger = new EmailServiceWithLogger(service, sendWith);


            //PROXY minta: ha a proxy osztaly feluletenek a hasznalatat ki lehet kenyszeriteni
            var serviceProxy = new EmailServiceProxy(service, sendWith);

            var message = EmailMessage.Factory(officeAddress, person.EmailAddress, "Udvozlet", "Boldog Szuletesnapot...");

            serviceWithLogger.Send(message);
        }
Exemplo n.º 2
0
        private static void TestBridge()
        {
            EmailMessage message = EmailMessage.Factory(
                from: EmailAddressFactory.GetNewAddress(address: "*****@*****.**", display: "Az elso cim"),
                to: EmailAddressFactory.GetNewAddress("*****@*****.**", "A masodik cim"),
                subject: "Test Subject",
                message: "Ez egy teszt uzenet...");


            //Implementor
            var strategy = AbstractSendWith.Factory <SendWith>();

            //Abstraction
            var service = new EmailService(strategy);

            service.Send(message);
            Console.WriteLine();

            var strategyExch = AbstractSendWith.Factory <SendWithExchange>();

            service = new EmailService(strategyExch);
            strategyExch.Send(message);
            Console.WriteLine();

            var strategySG = AbstractSendWith.Factory <SendWithSendGrid>();

            service = new EmailService(strategySG);
            strategySG.Send(message);
            Console.WriteLine();

            var strategyMandrill = AbstractSendWith.Factory <SendWithMandrill>();

            service = new EmailService(strategyMandrill);
            strategyMandrill.Send(message);
            Console.WriteLine();
        }