Hallo,

hier mal ein kleines Beispiel wie einfach man mit Spring.NET einen Dynamic Proxy erzeugen kann:
Code csharp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Aop.Framework;
using Spring.Aop;
using AopAlliance.Intercept;
 
namespace De.Tutorials.Spring
{
    public class SpringProxyGeneratorExample
    {
        public static void Main(string[] args)
        {
            ProxyFactory proxyFactory = new ProxyFactory(new BusinessService());
            proxyFactory.AddInterface(typeof(IBusinessService));
 
            proxyFactory.AddAdvice(new TracingInterceptor());
 
            IBusinessService businessService = (IBusinessService)proxyFactory.GetProxy();
            Console.WriteLine(businessService.businessOperation("Tom"));
        }
    }
 
    public interface IBusinessService{
        string businessOperation(string args);
    }
 
    public class BusinessService : IBusinessService
    {
 
        #region IBusinessService Members
 
        public string businessOperation(string args)
        {
            return args + " " + args;
        }
 
        #endregion
    }
 
    public class TracingInterceptor : IMethodInterceptor
    {
 
        #region IMethodInterceptor Members
 
        public object Invoke(IMethodInvocation invocation)
        {
            object result = null;
            Console.WriteLine("Before: " + invocation);
 
            result = invocation.Proceed();                
 
            Console.WriteLine("After: " + invocation);
            return result;
        }
 
        #endregion
    }
 
}

Ausgabe:
Code :
1
2
3
Before: Invocation: method 'businessOperation', arguments Tom; target is of Type [De.Tutorials.Spring.BusinessService
After: Invocation: method 'businessOperation', arguments Tom; target is of Type [De.Tutorials.Spring.BusinessService]
Tom Tom

Gruß Tom