1. public interface IPerson
    2. {
    3. void Method();
    4. }
    5. [Intercept(typeof(LogInterceptor))] // Person 使用 LogInterceptor拦截器
    6. public class Person : IPerson
    7. {
    8. public void Method()
    9. {
    10. Console.WriteLine("Method2");
    11. }
    12. }
    13. class Program
    14. {
    15. private static IContainer Container { get; set; }
    16. static void Main(string[] args)
    17. {
    18. var containerBuilder = new ContainerBuilder();
    19. containerBuilder.RegisterType<LogInterceptor>();
    20. containerBuilder.RegisterType<Person>().As<IPerson>().EnableInterfaceInterceptors();
    21. Container = containerBuilder.Build();
    22. using (var scope = Container.BeginLifetimeScope())
    23. {
    24. var person = scope.Resolve<IPerson>();
    25. person.Method();
    26. }
    27. Console.ReadLine();
    28. }
    29. }