Exemplo n.º 1
0
        static void Main(string[] args)
        {
            IContainerFactory containerFactory = new UnityContainerFactory();

            ContainerContext.ContainerFactory = containerFactory;
            BootStrapper.Configure(ContainerContext.Instance);


            IBankAccountService productService = BankAccountServiceFactory.CreateTransparentProxy();

            int branchCode = 1, accountNumber = 1000;
            BankAccountCollection bankAccounts;

            Run(() =>
            {
                //accounts will come from the service as expected
                bankAccounts = productService.GetBankAccounts(branchCode);
                foreach (var bankAccount in bankAccounts)
                {
                    System.Console.WriteLine(bankAccount.ToString());
                }
            });


            Run(() =>
            {
                //[Cache] it must come from cache
                bankAccounts = productService.GetBankAccounts(branchCode);
                foreach (var bankAccount in bankAccounts)
                {
                    System.Console.WriteLine(bankAccount.ToString());
                }
            });

            Run(() =>
            {
                //[Authorize] only user who has Admin role, can execute
                productService.WithDraw(accountNumber, 200000);
            });

            Run(() =>
            {
                //[Exception] we retrow friendly error message
                productService.Deposit(accountNumber, 200000);
            });

            System.Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            ContainerContext.Load();

            IBankAccountService productService = BankAccountServiceFactory.CreateTransparentProxy();

            int branchCode = 1, accountNumber = 1000;

            //servis üzerinden normal şekilde veriler gelecek
            BankAccountCollection bankAccounts = productService.GetBankAccounts(branchCode);

            foreach (var bankAccount in bankAccounts)
            {
                Console.WriteLine(bankAccount.ToString());
            }

            //cache üzerinden gelecek
            bankAccounts = productService.GetBankAccounts(branchCode);
            foreach (var bankAccount in bankAccounts)
            {
                Console.WriteLine(bankAccount.ToString());
            }

            Run(() =>
            {
                //[Authorize] içerinde Admin userı çalıştırabilir sadece
                productService.WithDraw(accountNumber, 200000);
            });

            Run(() =>
            {
                //[Exception] attribute için hata fırlatıyoruz içeride
                productService.Deposit(accountNumber, 200000);
            });

            Console.ReadLine();
        }