Hi Abp Zero,
We're using .net Core 2.1 and Angular 8.
For certain reason I would like to overwrite MultiTenantLocalizationSource with my own CustomMultiTenantLocalizationSource.

I tried to use following code in the PreInitialize() in ProjectCoreModule but it didn't work as other replaced services:
Configuration.ReplaceService<IMultiTenantLocalizationSource, CustomMultiTenantLocalizationSource>(DependencyLifeStyle.Transient);
Could you please advise how I coud replace the IMultiTenantLocalizationSource service?
Thank you
6 Answer(s)
-
0
IMultiTenantLocalizationSourceis not injected anywhere, so you can't replace its implementation that way.MultiTenantLocalizationSourceis instantiated directly inEnableDbLocalizationin LanguageManagementConfig.cs#L40.You can comment out the following line in your
WebCoreModuleand instantiate your own implementation.//Use database for language management Configuration.Modules.Zero().LanguageManagement.EnableDbLocalization();Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Thank you Aaron.
Hmm... then could I do this? Not sure if ILanguageManagementConfig is injected...
Configuration.ReplaceService<ILanguageManagementConfig, CustomLanguageManagementConfig>(); Configuration.Modules.Zero().LanguageManagement.EnableDbLocalization();Thank you, Robin
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi Robin, it is injected and you could do that.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Thank you Aaron. But somehow it's still not replace the service and going into the replaced implementation.
EnableDbLocalization() is still calling the default one instead of the CustomLanguageManagementConfig.EnableDbLocalization(). Seems LanguageManagementConfig has been initialized together with Configuration.Modules before everything else.
== Basically I had to use:
Configuration.ReplaceService<ILanguageManagementConfig, CustomLanguageManagementConfig>(); (new CustomLanguageManagementConfig(Configuration.IocManager, Configuration)).EnableDbLocalization();Is there any concern of calling customized EnableDbLocalization() in this way?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I would recommend Option 1.2 below.
Option 1: Register custom
ILanguageManagementConfigSeems LanguageManagementConfig has been initialized together with Configuration.Modules before everything else.
Good conjecture. More accurately,
ILanguageManagementConfigis instantiated on the first call toConfiguration.Modules.Zero().Configuration.Modules.Zero()is first called inYourProjectCoreModule.PreInitialize.ReplaceServiceonly runs inAbpKernalModule.Initialize, before other modules'Initialize.
Therefore, calling
ReplaceServicefor this inYourProjectWebCoreModule.PreInitializeis too late.Option 1.1: Directly register as default before
ILanguageManagementConfigis instantiatedYou can directly register
CustomLanguageManagementConfigas the default implementation before that first call.IocManager.IocContainer.Register( // Add this Component.For<ILanguageManagementConfig>() // Add this .ImplementedBy<CustomLanguageManagementConfig>() // Add this .IsDefault() // Add this ); // Add this //Declare entity types // Existing code Configuration.Modules.Zero().EntityTypes.Tenant = typeof(Tenant); // Existing codeOption 1.2: Add service before
ILanguageManagementConfigis registeredYou can
AddSingletontoIServiceCollectionin yourWebproject'sConfigureServices.services.AddSingleton<ILanguageManagementConfig, CustomLanguageManagementConfig>();Option 2: Instantiate custom
ILanguageManagementConfigwithout replacingIs there any concern of calling customized EnableDbLocalization() in this way?
In general, it is not preferable since
Configuration.Modules.Zero().LanguageManagementwould have the unexpected implementation if used elsewhere — but it's not used elsewhere.Therefore, in this case, there is no concern.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Thank you Aaron! That's very detailed and helpful. Wondering why I forgot the IsDefault() at the first place. It's working now!
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)