Skip to content

Reload/Refresh dynamically the app with UseBranchWithServices  #166

@AmbroiseCouissin

Description

@AmbroiseCouissin

Hi!

I have been using UseBranchWithServices for quite sometime now and it is great.
I'm using it for multitenancy with IdentityServer4. One branch per tenant.

The problem I have is that I want to create new tenants dynamically without restarting the app.

For example, if I want to add new branches with newly created tenants every 15s, I could do something like this:

            Task.Run(async () =>
            {
                while (true)
                {
                    List<string> oldTenantIds = TenantIds ?? new List<string>();
                    TenantIds = GetTenants(db);
                    var tenantIdsToSubscribe = TenantIds.Except(oldTenantIds).ToList();
                    if (tenantIdsToSubscribe.Count != 0)
                        foreach (string tenantId in tenantIdsToSubscribe)
                            app.UseBranchWithServices($"/{tenantId}",
                                services => GenericServicesConfig(services, db, tenantId),
                                appBuilder => GenericAppBuilderConfig(appBuilder));

                    await Task.Delay(15000);
                }
            });

But this doesn't seem to work.

If I do this on startup without the Task.Run/while(true)/Task.Delay, it works.

Any idea?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions