abp icon indicating copy to clipboard operation
abp copied to clipboard

Loading modules dynamically/conditionally.

Open maliming opened this issue 2 years ago • 2 comments

Is it possible to load module(s) at runtime instead of adding them using "DependsOnAttribute"? Or can you suggest a reasonable workaround compatible with Abp framework?

For example;

public class ModuleA : AbpModule 
{
    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        if (...)
        {
            context.Services.AddDependentModule(typeof(ModuleX));
        }
        else 
        {            
            context.Services.AddDependentModule(typeof(ModuleY));
        }
    }
}

Instead of

[DependsOn(typeof(ModuleX))]
[DependsOn(typeof(ModuleY))]
public class ModuleA : AbpModule
...

maliming avatar Sep 09 '22 08:09 maliming

When the PreConfigureServices method is executed, the dependencies of the modules have been determined, at this time we can't add new modules and their dependencies.

maliming avatar Sep 09 '22 09:09 maliming

PreConfigureServices is just an example.

Related Answer

y7MZ avatar Sep 09 '22 10:09 y7MZ

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 12 '22 05:11 stale[bot]

I would like to have something like this as well. I'm having issues due the following block does not honor "Redis:IsEnabled" flag.

            context.Services.AddSingleton<IDistributedLockProvider>(sp =>
            {
                var connection = ConnectionMultiplexer
                    .Connect(configuration["Redis:Configuration"]);
                return new 
                    RedisDistributedSynchronizationProvider(connection.GetDatabase());
            });

jrocha avatar Mar 14 '24 17:03 jrocha

hi @jrocha

Please create a new issue to discuss your case.

Thanks.

maliming avatar Mar 15 '24 01:03 maliming