首页 > 其他 > 详细

【转载】EF Core & Castle DynamicProxy基本用法(AOP)

时间:2020-05-06 00:25:56      阅读:67      评论:0      收藏:0      [点我收藏+]
03-EF Core笔记之查询数据
https://www.cnblogs.com/youring2/p/11186614.html
using (var context = new BloggingContext())
{
    var blogs = context.Blogs
        .Include(blog => blog.Posts)
        .Include(blog => blog.Owner)
        .ToList();
}

 

Castle DynamicProxy基本用法(AOP)
https://www.cnblogs.com/youring2/p/10962573.html

Autofac的集成#

Autofac集成了对DynamicProxy的支持,我们需要引用Autofac.Extras.DynamicProxy,然后创建容器、注册服务、生成实例、调用方法,我们来看下面的代码:

ContainerBuilder builder = new ContainerBuilder();
//注册拦截器
builder.RegisterType<LoggerInterceptor>().AsSelf();

//注册基础服务
builder.RegisterType<ConsoleLogger>().AsImplementedInterfaces();

//注册要拦截的服务
builder.RegisterType<ProductRepository>().AsImplementedInterfaces()
    .EnableInterfaceInterceptors()                  //启用接口拦截
    .InterceptedBy(typeof(LoggerInterceptor));      //指定拦截器

var container = builder.Build();

//解析服务
var productRepository = container.Resolve<IProductRepository>();

Product product = new Product() { Name = "Book" };
productRepository.Update(product);

  

 

【转载】EF Core & Castle DynamicProxy基本用法(AOP)

原文:https://www.cnblogs.com/sui84/p/12833845.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!