当前位置:网站首页>ABP vNext realizes automatic assignment and insertion of tenant ID

ABP vNext realizes automatic assignment and insertion of tenant ID

2021-01-23 16:43:40 itread01

![](https://img2020.cnblogs.com/blog/2193154/202101/2193154-20210123112126225-1958375181.png)## Background in use ABP vNext In the process , Because our user system is huge , So it's been developing with other businesses , When developing other business modules , We have always been misunderstood : Think of ABP vNext Automatic processing of tenants when data is added Id(TenantId) Automatic assignment insertion of . Until we started accessing the user license module , It turns out that's not the case .## The idea is to realize the automatic assignment of fields , And without perception , Our idea is to make similar interceptors , In the upper layer, add data related code to enter DbContext When , stay DbContext To deal with .## other ### The problem is to realize the 【 No perception 】, Even in the process of programming , We also don't want developers to have a clear sense that they are using processed DbContext, So I think of the relationship with Volo.Abp.EntityFrameworkCore.AbpDbContext Use the same name AbpDbContext.### The first thing we know about the solution is , stay C# in , If there are two namespace , Class with the same name , So what is the priority of the two classes . Suppose , The class we wrote is :TripleH.AbpDbContext. The namespace where we use this class is :TripleH.*.AClass. Then AClass Use in AbpDbContext When , Even if we quote Volo.Abp.EntityFrameworkCore The name space , It's also used at compile time TripleH.AbpDbContext. This is because ,C# The priority here is determined by , It's a priority Triple.* Under the namespace AbpDbContext This class , If not , It's going to go up , look for Triple Under the namespace AbpDbContext, If you find it , You'll use it directly , You don't need to refer to a namespace manually when you use it . Of course , If not , Will go to other namespace such as Volo.Abp.EntityFrameworkCore In search of .## Realize ```c#namespace TripleH{ public abstract class AbpDbContext

版权声明
本文为[itread01]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/01/20210123164135051b.html