Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft.Extensions.Configuration support #8764

Merged
merged 10 commits into from Jan 9, 2024

Conversation

ReubenBond
Copy link
Member

@ReubenBond ReubenBond commented Dec 7, 2023

This PR adds support for configuring clients and silos using Microsoft.Extensions.Configuration, otherwise known as IConfiguration.

The systems is extensible: providers of known kinds (Clustering, Reminders, GrainStorage, Streaming, BroadcastChannel) can be registered using an assembly-level RegisterProvider attribute like so:

[assembly: RegisterProvider("Static", "Clustering", "Client", typeof(StaticGatewayListProviderBuilder))]

internal sealed class StaticGatewayListProviderBuilder : IProviderBuilder<IClientBuilder>
{
    public void Configure(IClientBuilder builder, string name, IConfigurationSection configurationSection)
    {
        var endpoints = new List<IPEndPoint>();
        var gatewaysSection = configurationSection.GetSection("Gateways");
        foreach (var child in gatewaysSection.GetChildren())
        {
            if (IPEndPoint.TryParse(child.Value, out var ep))
            {
                endpoints.Add(ep);
            }
        }

        builder.UseStaticClustering([.. endpoints]);
    }
}

Perhaps we could make the configuration more open-ended by allowing the "kinds" themselves to be extensible. The only non-trivial part of doing that is that we need to know when a "kind" is a singleton ("Clustering", "Reminders") vs named (the others).
 
Here is an example configuration for a server:

{
  "Orleans": {
    "Name": "MyUniqueSiloName",
    "ClusterId": "fooboo",
    "ServiceId": "testarossa",
    "Endpoints": {
      "AdvertisedIPAddress": "127.0.0.1",
      "SiloListeningEndpoint": "127.0.0.1:11111"
    },
    "Clustering": {
      "ProviderType": "Development",
      "PrimarySiloEndPoint": "127.0.0.1:11111"
    },
    "Reminders": {
      "ProviderType": "Memory"
    },
    "GrainStorage": {
      "Default": {
        "ProviderType": "Memory"
      },
      "PubSubStore": {
        "ProviderType": "Memory"
      }
    },
    "Streaming": {
      "ItemUpdates": {
        "ProviderType": "Memory"
      }
    },
    "BroadcastChannel": {
      "MyNotifications": {
        "ProviderType": "Default"
      }
    }
  }
}

Here is an example configuration for a corresponding client:

{
  "Orleans": {
    "ClusterId": "fooboo",
    "ServiceId": "testarossa",
    "Clustering": {
      "ProviderType": "Static",
      "Gateways": [ "127.0.0.1:30000" ]
    },
    "Streaming": {
      "ItemUpdates": {
        "ProviderType": "Memory"
      }
    },
    "BroadcastChannel": {
      "MyNotifications": {
        "ProviderType": "Default"
      }
    }
  }
}

TODO

  • Add remaining providers
  • Add configuration test coverage (TestingHost uses this now, but we can add more specific tests)

Later

  • Add documentation for configuring Orleans using Microsoft.Extensions.Configuration
  • Add ConfigurationSchema.json files once they're supported (currently Aspire & VS only)

Fixes #6565

Microsoft Reviewers: Open in CodeFlow

@ReubenBond ReubenBond marked this pull request as ready for review December 12, 2023 00:32
@ReubenBond
Copy link
Member Author

@benjaminpetit ptal

@benjaminpetit benjaminpetit enabled auto-merge (squash) January 9, 2024 15:52
@benjaminpetit benjaminpetit merged commit cab108e into dotnet:main Jan 9, 2024
16 of 19 checks passed
@jdom
Copy link
Member

jdom commented Jan 30, 2024

This is pretty cool! :)

@ReubenBond ReubenBond deleted the feature/iconfiguration/1 branch January 30, 2024 21:24
@github-actions github-actions bot locked and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

orleans configurable via IConfiguration
3 participants