简单易用的AOP/IOC框架

Source:

http://www.codeproject.com/KB/Articles/684613/Working/AopIoc.zip

 

Introduction 

Supper framework is used to achieve IOC and AOP. It's easy to use.

Background 

Decoupling Relations? intercept  before and after the method?

Then, supper framework is a best way if you choose. 

Using the code

Easy step to use:  

1. Registe service: 

var container = new Container(obj => obj.
                RegisteService<IRun, Quicker>(RegType.Multiple).
                RegisteService<IPersonService, StudentService>(RegType.Multiple)); 


2. Use your service:  
var student = container.Resolve<IPersonService>();
student.Shout("excute success...");

3. Write AOP:  
    internal class Permission : AopAttribute
    {
        public override void CustomBeforeRun(IMethodCallMessage sender, object e)
        {
            Console.WriteLine("Pre Fire a method..." + sender.MethodName);
            Result.EnableInterruptExcute = false;
        }

        public override void CustomAfterRun(IMethodCallMessage sender, object e)
        {
            Console.WriteLine("Has Fired a method..." + sender.MethodName);
            Result.EnableInterruptExcute = false;
        }
    } 

4. Use AOP: 
   internal class StudentService : BaseUnity, IPersonService
    {
        private readonly IRun _runner;

        public StudentService(IRun ps)
        {
            _runner = ps;
        }

        [Permission]
        public void Shout(string content)
        {
            Console.WriteLine("Student shouting..." + content);
            _runner.RunSpeed();
        }
    } 

Points of Interest   

You can see in class "StudentService", this class is depend on IRun. Our framework also will support automated assembly object  

posted @ 2013-11-20 22:54  China Soft  阅读(508)  评论(0编辑  收藏  举报