• Data模块


    一、模块定义

    1、DataSeedOptions的属性DataSeedContributorList

     只有实现IDataSeedContributor,自动增加列表里面去

    2、配置DbConnectionOptions

        public override void ConfigureServices(ServiceConfigurationContext context)
            {
                var configuration = context.Services.GetConfiguration();
    
                Configure<DbConnectionOptions>(configuration);
    
                context.Services.AddSingleton(typeof(IDataFilter<>), typeof(DataFilter<>));
            }

    二、数据软删除,扩展字典

    ISoftDelete

    IHasExtraProperties

    三、连接字符串解析,及实现(结合多租户)

      public interface IConnectionStringResolver
        {
            [NotNull]
            string Resolve(string connectionStringName = null);
        }

    四、种子数据写入

       public interface IDataSeeder
        {
            Task SeedAsync(DataSeedContext context);
        }

    护展方法

       public static Task SeedAsync(this IDataSeeder seeder, Guid? tenantId = null)
            {
                return seeder.SeedAsync(new DataSeedContext(tenantId));
            }

    在实现类,调用IDataSeedContributor的实现类,SeedAsync方法

     [UnitOfWork]
            public virtual async Task SeedAsync(DataSeedContext context)
            {
                using (var scope = ServiceScopeFactory.CreateScope())
                {
                    foreach (var contributorType in Options.Contributors)
                    {
                        var contributor = (IDataSeedContributor) scope
                            .ServiceProvider
                            .GetRequiredService(contributorType);
    
                        await contributor.SeedAsync(context);
                    }
                }
            }

    DataSeedContext,构造函数要求写入租户Id(必须),自定义属性 Dictionary<string, object> Properties { get; }

       public DataSeedContext(Guid? tenantId = null)
            {
                TenantId = tenantId;
                Properties = new Dictionary<string, object>();
            }
     public interface IDataSeedContributor
        {
            Task SeedAsync(DataSeedContext context);
        }

      见具体实现方法

        [UnitOfWork]
            public virtual async Task<IdentityDataSeedResult> SeedAsync(
                string adminEmail,
                string adminPassword,
                Guid? tenantId = null)
            {
                Check.NotNullOrWhiteSpace(adminEmail, nameof(adminEmail));
                Check.NotNullOrWhiteSpace(adminPassword, nameof(adminPassword));
    
                var result = new IdentityDataSeedResult();
    
                //"admin" user
                const string adminUserName = "admin";
                var adminUser = await _userRepository.FindByNormalizedUserNameAsync(
                    _lookupNormalizer.Normalize(adminUserName)
                );
    
                if (adminUser != null)
                {
                    return result;
                }
    
                adminUser = new IdentityUser(
                    _guidGenerator.Create(),
                    adminUserName,
                    adminEmail,
                    tenantId
                )
                {
                    Name = adminUserName
                };
    
                (await _userManager.CreateAsync(adminUser, adminPassword)).CheckErrors();
                result.CreatedAdminUser = true;
    
                //"admin" role
                const string adminRoleName = "admin";
                var adminRole = await _roleRepository.FindByNormalizedNameAsync(_lookupNormalizer.Normalize(adminRoleName));
                if (adminRole == null)
                {
                    adminRole = new IdentityRole(
                        _guidGenerator.Create(),
                        adminRoleName,
                        tenantId
                    )
                    {
                        IsStatic = true,
                        IsPublic = true
                    };
    
                    (await _roleManager.CreateAsync(adminRole)).CheckErrors();
                    result.CreatedAdminRole = true;
                }
    
                (await _userManager.AddToRoleAsync(adminUser, adminRoleName)).CheckErrors();
    
                return result;
            }

    五、IDataFilter

    获取到DataFilter<T>实例,由于初始化,根据AbpDataFilterOption存储State,若没特定(查不到),默认是true的,若指定根据指定值

    也可以临时指定设置Disposeable方法,执行完回归原来的值。

    DataFilterState,存储着每个类型是否作数据筛选,默认是True的,它的IsEnable若没有

    DataFilterOptions

       public interface IDataFilter<TFilter>
            where TFilter : class
        {
            IDisposable Enable();
    
            IDisposable Disable();
    
            bool IsEnabled { get; }
        }
  • 相关阅读:
    利用sklearn训练LDA主题模型及调参详解
    关联规则挖掘:Apriori算法(基于Groceries数据集)
    极大连通子图与极小连通子图
    TCP协议“三次握手”与“四次挥手”详解(下)
    TCP协议“三次握手”与“四次挥手”详解(上)
    95题--不同的二叉搜索树II(java、中等难度)
    96题--不同的二叉搜索树(java、中等难度)
    CRC循环冗余校验---模2除法解析
    黑盒测试用例设计方法总结
    软件配置管理和软件维护的区别【详细】
  • 原文地址:https://www.cnblogs.com/cloudsu/p/11190664.html
Copyright © 2020-2023  润新知