文章预览
基于依赖注入使用 EF Interceptor Intro 在上一篇文章中简单介绍了下 借助 Interceptor 实现属性的自动更新 ,有朋友问如何在 interceptor 中使用使用依赖注入 Sample DbContext sample: file sealed class BlogPostContext ( DbContextOptions options ): DbContext ( options ) { public DbSet Posts { get ; set ; } = default !; } public class BlogPost { public int Id { get ; set ; } [ StringLength(64) ] public required string Title { get ; set ; } public DateTimeOffset UpdatedAt { get ; set ; } [ StringLength(64) ] public string UpdatedBy { get ; set ; } = default !; } 这里 BlogPost 定义了一个 UpdatedBy 我们也通过 interceptor 来实现自动更新,与之前不同的是,我们通过从依赖注入中获取 UpdatedBy 信息,我们定义一个 IUserIdProvider 来获取更新用户的信息,并且提
………………………………