IntentArchitect / Support

A repository dedicated to handling issues and support queries
3 stars 0 forks source link

Multi-tenant: Expose builders #79

Open shainegordon opened 10 months ago

shainegordon commented 10 months ago

What problem are you trying to solve?

Often, we want to use Intent Architect to bootstrap the application but still allow us to configure it.

Take multi-tenant for example

Here is the generated code

services.AddMultiTenant<TenantInfo>()
    .WithConfigurationStore() // See https://www.finbuckle.com/MultiTenant/Docs/v6.12.0/Stores#configuration-store
    .WithHeaderStrategy("X-Tenant-Identifier"); // See https://www.finbuckle.com/MultiTenant/Docs/v6.12.0/Strategies#header-strategy

This works great, but let's say I want to add a fallback tenant.

The only way to do that is to change the code.

//IntentIgnore
//IntentMatch("services.AddMultiTenant<TenantInfo>()")
services.AddMultiTenant<TenantInfo>()
    .WithConfigurationStore() // See https://www.finbuckle.com/MultiTenant/Docs/v6.12.0/Stores#configuration-store
    .WithHeaderStrategy("X-Tenant-Identifier") // See https://www.finbuckle.com/MultiTenant/Docs/v6.12.0/Strategies#header-strategy
    .WithStaticStrategy("realm-digital"); 

Again, this works, but I have opted out of Intent Architect managed code, so changing this from, say "Header Strategy" to "Host Strategy" in Intent Application settings would not result in code change.

Describe the solution you'd like

Builders should be exposed so that they can be extended.

e.g.

public static IServiceCollection ConfigureMultiTenancy(
            this IServiceCollection services,
            IConfiguration configuration)
        {

            var builder = services.AddMultiTenant<TenantInfo>()
                .WithConfigurationStore() // See https://www.finbuckle.com/MultiTenant/Docs/v6.12.0/Stores#configuration-store
                .WithHeaderStrategy("X-Tenant-Identifier"); // See https://www.finbuckle.com/MultiTenant/Docs/v6.12.0/Strategies#header-strategy

            // I can now safely add this line, along with `[IntentManaged(Mode.Merge)]`
            builder.WithStaticStrategy("realm-digital"); 
            return services;
        }

This example is multi-tenant specific, but should apply to other builders.

joelsteventurner commented 10 months ago

Hi @shainegordon

I've logged a ticket for the team to discuss and will revert.

We as a general rule try to produce code which is in line with what a developer would manually code. In this example it would be weird to see a "var builder =", where the builder is never used, which is what anyone not extending this pattern would get.

The other options here would be: a) to put that statement on Ignore, which you have mentioned, I don't think this is a bad option given this setup code would generally not change often. b) have a custom module which extends the builder statement, adding in your custom code

joelsteventurner commented 10 months ago

Have chatted to the team and we've logged a ticket to see if we can extend the code management system to allow for an "Intent Ignore" on the Chained method invocation.