Exemplo n.º 1
0
        //定义单例模式将PolicyInjection.Create<UserOperation>()产生的这个对象传出去,这样就避免了在调用处写这些东西
        public static UserOperation GetInstance()
        {
            if (oUserOpertion == null)
            {
                oUserOpertion = PolicyInjection.Create <UserOperation>();
            }

            return(oUserOpertion);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            #region 一、静态代理(AOP_Static.cs)
            //try
            //{
            //    Order order = new Order() { Id = 1, Name = "lee", Count = 10, Price = 100.00, Desc = "订单测试" };
            //    IOrderProcessor orderprocessor = new OrderProcessorDecorator(new OrderProcessor());
            //    orderprocessor.Submit(order);
            //    Console.ReadLine();
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}
            #endregion

            #region 二、动态代理——使用.Net Remoting/RealProxy(AOP_Dynamic1.cs)
            //try
            //{
            //    User user = new User() { Name = "lee", PassWord = "******" };
            //    UserProcessor userprocessor = TransparentProxy.Create<UserProcessor>();
            //    userprocessor.RegUser(user);
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}
            #endregion

            #region  、动态代理——使用EnterPrise Lib实现拦截(AOP_Dynamic2.cs)
            try
            {
                var oUserTest1 = new User()
                {
                    Name = "test2222", PassWord = "******"
                };
                var oUserTest2 = new User()
                {
                    Name = "test3333", PassWord = "******"
                };
                var oUser = UserOperation.GetInstance();
                oUser.Test(oUserTest1);
                oUser.Test2(oUserTest1, oUserTest2);
            }
            catch (Exception ex)
            {
                //throw;
            }
            #endregion
        }