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

Use OptionsBuilder to allow chaining Configure calls for providers #3696

Merged
merged 4 commits into from
Nov 21, 2017

Conversation

jdom
Copy link
Member

@jdom jdom commented Nov 21, 2017

I temporarily copied the implementation of OptionsBuilder into the Orleans codebase, but the plan is to delete it once Microsoft.Extensions.Options v2.1 is released, and includes these. I put them in an Orleans namespace to avoid collisions if they co-exist for a short while.

For an explanation why OptionsBuilder is better than having extension method overloads for every variation of how to configure, see the PR itself: aspnet/Options#238

This will even be a lot more useful once we start using named options for our named service providers configuration.

I migrated our current extension methods for the gateway list and membership providers to use this. I did preserve the overload that takes Action<TOptions>, and the reasoning is explained and shown in the second commit in this PR (let me know if you are OK with this or prefer not to have that overload, which is less boilerplate code for us, but potentially a harder to use API for the common case).

In the future, we can also port this PR that was merged today and builds on top of OptionsBuilder: aspnet/Options#239 We already do a very similar thing here)

jdom added 3 commits November 21, 2017 12:22
Configuring with just a delegate is probably the most common scenario, so add back overloads that take an `Action<TOptions>` and not just have `Action<OptionsBuilder<TOptions>>` which requires more ceremony for the end user.
This allows this again:
`services.UseAzureTableGatewayListProvider(gatewayOptions => gatewayOptions.ConnectionString = TestDefaultConfiguration.DataConnectionString)`

Without the overload, users would have to do this:
`services.UseAzureTableGatewayListProvider(ob => ob.Configure(gatewayOptions => gatewayOptions.ConnectionString = TestDefaultConfiguration.DataConnectionString))`
@jdom jdom added this to the 2.0.0 milestone Nov 21, 2017
@@ -0,0 +1,74 @@
// Copyright (c) .NET Foundation. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,33 @@
// Copyright (c) .NET Foundation. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
return builder.ConfigureServices(services => services.UseConsulGatewayListProvider(configuration));
return builder.ConfigureServices(services => services.UseConsulGatewayListProvider(configureOptions));
}

/// <summary>
/// Configure DI container with ConsuleBasedMemebership
Copy link
Member

@ReubenBond ReubenBond Nov 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo on Consul. Repeated below

@@ -25,21 +22,15 @@ public static class ZooKeeperHostingExtensions
/// <summary>
/// Configure siloHostBuilder with ZooKeeperMembership
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Configures the silo to use ZooKeeper for cluster membership" - but it's perhaps out of scope for this pr to change the comment

}

/// <summary>
/// Add an <see cref="StaticGatewayListProvider"/> and configure it using <paramref name="configuration"/>
/// Add an <see cref="StaticGatewayListProvider"/> and configure it using <paramref name="configureOptions"/>
/// </summary>
/// <param name="collection"></param>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other files, empty params were removed. Could do the same here

return collection
.Configure<StaticGatewayListProviderOptions>(configuration)
.AddSingleton<IGatewayListProvider, StaticGatewayListProvider>();
configureOptions?.Invoke(collection.AddOptions<StaticGatewayListProviderOptions>());
Copy link
Member

@ReubenBond ReubenBond Nov 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given this can be null, should the param have a default value of null? Fine either way to me

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, scrap that - a default value would make overload resolution ugly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really making that call in this PR, just porting it. Although responding to this particular thing, it might be that we don't really want null, and potentially throw an argument exception... I don't really know at this point which behavior to choose, so I'll leave it undefined for now, unless you already thought through it and can recommend one

@ReubenBond
Copy link
Member

@dotnet-bot test bvt

@ReubenBond ReubenBond merged commit e65418a into dotnet:master Nov 21, 2017
@jdom jdom deleted the config-builder branch November 21, 2017 23:37
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
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.

4 participants