public interface IPerson
{
void Method();
}
[Intercept(typeof(LogInterceptor))] // Person 使用 LogInterceptor拦截器
public class Person : IPerson
{
public void Method()
{
Console.WriteLine("Method2");
}
}
class Program
{
private static IContainer Container { get; set; }
static void Main(string[] args)
{
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterType<LogInterceptor>();
containerBuilder.RegisterType<Person>().As<IPerson>().EnableInterfaceInterceptors();
Container = containerBuilder.Build();
using (var scope = Container.BeginLifetimeScope())
{
var person = scope.Resolve<IPerson>();
person.Method();
}
Console.ReadLine();
}
}