• 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; }
        }
  • 相关阅读:
    卡拉OK歌词原理和实现高仿Android网易云音乐
    LRC歌词原理和实现高仿Android网易云音乐
    Android项目实战之高仿网易云音乐创建项目和配置
    Android项目实战之高仿网易云音乐项目介绍
    WPS for Linux 与统一操作系统 UOS 完成适配,WP越来越强大
    2020 年,Linux 设备或将爆炸式增长
    随机电话号码生成器怎么在线使用?
    Chrome是老大,Firefox 是老二,Edge 不是老三
    2020 年的云世界三个方面:新联盟、无服务器和安全挑战
    电话号码生成器手机版,苹果和安卓手机均可用
  • 原文地址:https://www.cnblogs.com/cloudsu/p/11190664.html
Copyright © 2020-2023  润新知