• .NET Core + Abp踩坑和填坑记录(1)


    1. Net Core 的DI和Abp的DI并存

    Startup中 ConfigureServices返回值改为IServiceProvider

    在ConfigureServices最后调用return services.AddAbp<AppModule>();

    AppModule是一个自己实现的继承AbpModule的类,用于程序集注入和其他配置初始化。

    比如

    [DependsOn(
            typeof(DomainModule),
            typeof(InfrastructureModule),
            typeof(AbpAspNetCoreModule))]
        public class AppModule : AbpModule
        {
            private readonly IConfigurationRoot appConfiguration;
    
            public AppModule(IHostingEnvironment env)
            {
                appConfiguration = AppConfigurations.Get(env.ContentRootPath, env.EnvironmentName);
            }
    
            public override void PreInitialize()
            {
                Configuration.DefaultNameOrConnectionString = appConfiguration["Database:ConnectionString"]; // 注意此处,后面有用
                Configuration.UnitOfWork.Timeout = TimeSpan.FromSeconds(5);
            }
    
            public override void Initialize()
            {
                IocManager.RegisterAssemblyByConvention(Assembly.GetEntryAssembly());
            }
        }

    2. Abp.EntityFrameworkCore的问题

    .NET Core下使用的是EfCoreRepositoryBase类来作为Repository的基类

    使用DDD+Abp的时候发现Repository的Insert没有自动持久化到数据库,文档中是说会在UOW完成的时候自动调用持久化方法。

    EfCoreRepositoryBase的构造函数需要IDbContextProvider,其中有两个实现:SimpleDbContextProvider不支持UOW,UnitOfWorkDbContextProvider才支持UOW。

    IDbContextProvider需要提供DBContext来完成构造,DBContext又需要DBContextOption,

    所以要注册以下依赖:

    DBContextOption,DBContext,Repository,UnitOfWorkDBContextProvider。

    还有一点是UnitOfWorkDBContextProvider的调用链中会用到Configuration.DefaultNameOrConnectionString用于建立数据库连接,这个设置要在AbpModule实现中完成,也就是第1点中代码注释提到的位置,默认是"Default",所以要么把ConnectionString的键名改成Default,要么在AbpModule实现中修改Configuration.DefaultNameOrConnectionString

  • 相关阅读:
    用react+redux+webpack搭建项目一些疑惑
    ajax基本原理实现
    jsonp详细原理之一
    因为文件共享不安全,所以你不能连接到文件共享
    python xml模块
    python os模块
    python tickle模块与json模块
    python datetime模块
    python sys模块
    python time模块
  • 原文地址:https://www.cnblogs.com/zonciu/p/6719957.html
Copyright © 2020-2023  润新知