Dear Support
Sorry, I am sure I am overlooking something but in 4.0.2 I used in the ApbModule:
public override void PreInitialize() { if (!SkipDbContextRegistration) { Configuration.ReplaceService<IConnectionStringResolver, myConnectionStringResolver>(); ...
but this is not working anymore (I assume the ReplaceService notation changed in AbpModule). Can you please point me to the correcty way to use an own IConnectionStringResolver (ASP.NET MVC CORE + JQUERY) ?
Kind regards Andreas
<br> <br>
6 Answer(s)
-
0
I have not reproduced your question, please share more details and code.
-
0
Dear Maliming
Please as follow, the code is in the cwadmin.EntityFrameworkCore project, EntityFrameworkCore folder:
[DependsOn( typeof(AbpZeroCoreEntityFrameworkCoreModule), typeof(cwadminCoreModule), typeof(AbpZeroCoreIdentityServerEntityFrameworkCoreModule) )] public class cwadminEntityFrameworkCoreModule : AbpModule { /* Used it tests to skip dbcontext registration, in order to use in-memory database of EF Core */ public bool SkipDbContextRegistration { get; set; } public bool SkipDbSeed { get; set; } public override void PreInitialize() { if (!SkipDbContextRegistration) { Configuration.ReplaceService<IConnectionStringResolver, myConnectionStringResolver>(); Configuration.Modules.AbpEfCore().AddDbContext<cwadminDbContext>(options => { if (options.ExistingConnection != null) { cwadminDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection); } else { cwadminDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString); } }); Configuration.Modules.AbpEfCore().AddDbContext<cwTopologySwitchDbContext>(options => { if (options.ExistingConnection != null) { cwTopologySwitchDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection); } else { cwTopologySwitchDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString); } }); Configuration.Modules.AbpEfCore().AddDbContext<cwCauDbContext>(options => { if (options.ExistingConnection != null) { cwCauDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection); } else { cwCauDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString); } }); Configuration.Modules.AbpEfCore().AddDbContext<cwClientDbContext>(options => { if (options.ExistingConnection != null) { cwClientDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection); } else { cwClientDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString); } }); } // Uncomment below line to write change logs for the entities below: Configuration.EntityHistory.Selectors.Add("cwadminEntities", EntityHistoryHelper.TrackedTypes); Configuration.CustomConfigProviders.Add(new EntityHistoryConfigProvider(Configuration)); } public override void Initialize() { IocManager.RegisterAssemblyByConvention(typeof(cwadminEntityFrameworkCoreModule).GetAssembly()); } public override void PostInitialize() { var configurationAccessor = IocManager.Resolve<IAppConfigurationAccessor>(); using (var scope = IocManager.CreateScope()) { if (!SkipDbSeed && scope.Resolve<DatabaseCheckHelper>().Exist(configurationAccessor.Configuration["ConnectionStrings:Default"])) { SeedHelper.SeedHostDb(IocManager); } } } }
It follows the recomendation for multiple databases found in https://stackoverflow.com/questions/49243891/how-to-use-multiples-databases-in-abp-core-zero/49572121#49572121
Kind regards Andreas
-
0
Try Resolve
IConnectionStringResolver
under the PostInitialize method to see if it is correct?var connectionStringResolver = IocManager.Resolve<IConnectionStringResolver>();
public override void PostInitialize() { var configurationAccessor = IocManager.Resolve<IAppConfigurationAccessor>(); var connectionStringResolver = IocManager.Resolve<IConnectionStringResolver>(); // ... }
-
0
Dear Maliming
Thank you for your feedback. Sorry, maybe my question was missleading. I would like to understand how I should register my own implementation if IConnectionStringResolver because Configuration.ReplaceService<IConnectionStringResolver, myConnectionStringResolver>(); does not work anymore with APB 4.1.0.
Kind regards Andreas
-
0
hi schneana.
abp v4.1 did not modify the features you mentioned. https://github.com/aspnetboilerplate/aspnetboilerplate/releases/tag/v4.1.0
-
0
Dear Maliming
Many thanks for your feedback and for the link. You are right, investigating from the link I could trace down the issue. As usual the issue was infront of the keyboard, in this case I had a reference to Abp.Configuration.Startup. AbpStartupConfigurationExtensions was therefore not available togeter with the extesion on .ReplaceService<,>.
Again many thanks for your swift response.
Kind regard Andreas