Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Microsoft.Extensions.Configuration support (#8764)
* WIP - Use IConfiguration to configure silos and clients, including providers * More wip * BROKEN WIP * more * More providers * Test fixes * Add explainer comment * Fix HeterogeneousTests * Add missing Redis Client clustering directive * Remove playground projects
- Loading branch information
1 parent
c597141
commit cab108e
Showing
89 changed files
with
1,988 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
src/AWS/Orleans.Clustering.DynamoDB/DynamoDBClusteringProviderBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
using System; | ||
using Microsoft.Extensions.Configuration; | ||
using Orleans; | ||
using Orleans.Hosting; | ||
using Orleans.Providers; | ||
|
||
[assembly: RegisterProvider("DynamoDB", "Clustering", "Silo", typeof(DynamoDBClusteringProviderBuilder))] | ||
[assembly: RegisterProvider("DynamoDB", "Clustering", "Client", typeof(DynamoDBClusteringProviderBuilder))] | ||
|
||
namespace Orleans.Hosting; | ||
|
||
internal sealed class DynamoDBClusteringProviderBuilder : IProviderBuilder<ISiloBuilder>, IProviderBuilder<IClientBuilder> | ||
{ | ||
public void Configure(ISiloBuilder builder, string name, IConfigurationSection configurationSection) | ||
{ | ||
builder.UseDynamoDBClustering(options => | ||
{ | ||
var accessKey = configurationSection[nameof(options.AccessKey)]; | ||
if (!string.IsNullOrEmpty(accessKey)) | ||
{ | ||
options.AccessKey = accessKey; | ||
} | ||
var secretKey = configurationSection[nameof(options.SecretKey)]; | ||
if (!string.IsNullOrEmpty(secretKey)) | ||
{ | ||
options.SecretKey = secretKey; | ||
} | ||
var region = configurationSection[nameof(options.Service)] ?? configurationSection["Region"]; | ||
if (!string.IsNullOrEmpty(region)) | ||
{ | ||
options.Service = region; | ||
} | ||
var token = configurationSection[nameof(options.SecretKey)]; | ||
if (!string.IsNullOrEmpty(token)) | ||
{ | ||
options.Token = token; | ||
} | ||
var profileName = configurationSection[nameof(options.SecretKey)]; | ||
if (!string.IsNullOrEmpty(profileName)) | ||
{ | ||
options.ProfileName = profileName; | ||
} | ||
var tableName = configurationSection[nameof(options.TableName)]; | ||
if (!string.IsNullOrEmpty(tableName)) | ||
{ | ||
options.TableName = tableName; | ||
} | ||
if (int.TryParse(configurationSection[nameof(options.ReadCapacityUnits)], out var rcu)) | ||
{ | ||
options.ReadCapacityUnits = rcu; | ||
} | ||
if (int.TryParse(configurationSection[nameof(options.WriteCapacityUnits)], out var wcu)) | ||
{ | ||
options.WriteCapacityUnits = wcu; | ||
} | ||
if (bool.TryParse(configurationSection[nameof(options.UseProvisionedThroughput)], out var upt)) | ||
{ | ||
options.UseProvisionedThroughput = upt; | ||
} | ||
if (bool.TryParse(configurationSection[nameof(options.CreateIfNotExists)], out var cine)) | ||
{ | ||
options.CreateIfNotExists = cine; | ||
} | ||
if (bool.TryParse(configurationSection[nameof(options.UpdateIfExists)], out var uie)) | ||
{ | ||
options.UpdateIfExists = uie; | ||
} | ||
}); | ||
} | ||
|
||
public void Configure(IClientBuilder builder, string name, IConfigurationSection configurationSection) | ||
{ | ||
builder.UseDynamoDBClustering(options => | ||
{ | ||
var accessKey = configurationSection[nameof(options.AccessKey)]; | ||
if (!string.IsNullOrEmpty(accessKey)) | ||
{ | ||
options.AccessKey = accessKey; | ||
} | ||
var secretKey = configurationSection[nameof(options.SecretKey)]; | ||
if (!string.IsNullOrEmpty(secretKey)) | ||
{ | ||
options.SecretKey = secretKey; | ||
} | ||
var region = configurationSection[nameof(options.Service)] ?? configurationSection["Region"]; | ||
if (!string.IsNullOrEmpty(region)) | ||
{ | ||
options.Service = region; | ||
} | ||
var token = configurationSection[nameof(options.SecretKey)]; | ||
if (!string.IsNullOrEmpty(token)) | ||
{ | ||
options.Token = token; | ||
} | ||
var profileName = configurationSection[nameof(options.SecretKey)]; | ||
if (!string.IsNullOrEmpty(profileName)) | ||
{ | ||
options.ProfileName = profileName; | ||
} | ||
var tableName = configurationSection[nameof(options.TableName)]; | ||
if (!string.IsNullOrEmpty(tableName)) | ||
{ | ||
options.TableName = tableName; | ||
} | ||
if (int.TryParse(configurationSection[nameof(options.ReadCapacityUnits)], out var rcu)) | ||
{ | ||
options.ReadCapacityUnits = rcu; | ||
} | ||
if (int.TryParse(configurationSection[nameof(options.WriteCapacityUnits)], out var wcu)) | ||
{ | ||
options.WriteCapacityUnits = wcu; | ||
} | ||
if (bool.TryParse(configurationSection[nameof(options.UseProvisionedThroughput)], out var upt)) | ||
{ | ||
options.UseProvisionedThroughput = upt; | ||
} | ||
if (bool.TryParse(configurationSection[nameof(options.CreateIfNotExists)], out var cine)) | ||
{ | ||
options.CreateIfNotExists = cine; | ||
} | ||
if (bool.TryParse(configurationSection[nameof(options.UpdateIfExists)], out var uie)) | ||
{ | ||
options.UpdateIfExists = uie; | ||
} | ||
}); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
src/AWS/Orleans.Persistence.DynamoDB/Hosting/DynamoDBGrainStorageProviderBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using System; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using Orleans; | ||
using Orleans.Configuration; | ||
using Orleans.Hosting; | ||
using Orleans.Providers; | ||
using Orleans.Storage; | ||
|
||
[assembly: RegisterProvider("DynamoDB", "GrainStorage", "Silo", typeof(DynamoDBGrainStorageProviderBuilder))] | ||
|
||
namespace Orleans.Hosting; | ||
|
||
internal sealed class DynamoDBGrainStorageProviderBuilder : IProviderBuilder<ISiloBuilder> | ||
{ | ||
public void Configure(ISiloBuilder builder, string name, IConfigurationSection configurationSection) | ||
{ | ||
builder.AddDynamoDBGrainStorage( | ||
name, | ||
(OptionsBuilder<DynamoDBStorageOptions> optionsBuilder) => optionsBuilder.Configure<IServiceProvider>((options, services) => | ||
{ | ||
var accessKey = configurationSection[nameof(options.AccessKey)]; | ||
if (!string.IsNullOrEmpty(accessKey)) | ||
{ | ||
options.AccessKey = accessKey; | ||
} | ||
var secretKey = configurationSection[nameof(options.SecretKey)]; | ||
if (!string.IsNullOrEmpty(secretKey)) | ||
{ | ||
options.SecretKey = secretKey; | ||
} | ||
var region = configurationSection[nameof(options.Service)] ?? configurationSection["Region"]; | ||
if (!string.IsNullOrEmpty(region)) | ||
{ | ||
options.Service = region; | ||
} | ||
var token = configurationSection[nameof(options.SecretKey)]; | ||
if (!string.IsNullOrEmpty(token)) | ||
{ | ||
options.Token = token; | ||
} | ||
var profileName = configurationSection[nameof(options.SecretKey)]; | ||
if (!string.IsNullOrEmpty(profileName)) | ||
{ | ||
options.ProfileName = profileName; | ||
} | ||
var serviceId = configurationSection[nameof(options.ServiceId)]; | ||
if (!string.IsNullOrEmpty(serviceId)) | ||
{ | ||
options.ServiceId = serviceId; | ||
} | ||
var tableName = configurationSection[nameof(options.TableName)]; | ||
if (!string.IsNullOrEmpty(tableName)) | ||
{ | ||
options.TableName = tableName; | ||
} | ||
if (int.TryParse(configurationSection[nameof(options.ReadCapacityUnits)], out var rcu)) | ||
{ | ||
options.ReadCapacityUnits = rcu; | ||
} | ||
if (int.TryParse(configurationSection[nameof(options.WriteCapacityUnits)], out var wcu)) | ||
{ | ||
options.WriteCapacityUnits = wcu; | ||
} | ||
if (bool.TryParse(configurationSection[nameof(options.UseProvisionedThroughput)], out var upt)) | ||
{ | ||
options.UseProvisionedThroughput = upt; | ||
} | ||
if (bool.TryParse(configurationSection[nameof(options.CreateIfNotExists)], out var cine)) | ||
{ | ||
options.CreateIfNotExists = cine; | ||
} | ||
if (bool.TryParse(configurationSection[nameof(options.UpdateIfExists)], out var uie)) | ||
{ | ||
options.UpdateIfExists = uie; | ||
} | ||
if (bool.TryParse(configurationSection[nameof(options.DeleteStateOnClear)], out var dsoc)) | ||
{ | ||
options.DeleteStateOnClear = dsoc; | ||
} | ||
if (TimeSpan.TryParse(configurationSection[nameof(options.TimeToLive)], out var ttl)) | ||
{ | ||
options.TimeToLive = ttl; | ||
} | ||
var serializerKey = configurationSection["SerializerKey"]; | ||
if (!string.IsNullOrEmpty(serializerKey)) | ||
{ | ||
options.GrainStorageSerializer = services.GetRequiredKeyedService<IGrainStorageSerializer>(serializerKey); | ||
} | ||
})); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/AWS/Orleans.Reminders.DynamoDB/DynamoDBRemindersProviderBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Orleans; | ||
using Orleans.Hosting; | ||
using Orleans.Providers; | ||
|
||
[assembly: RegisterProvider("DynamoDB", "Reminders", "Silo", typeof(DynamoDBRemindersProviderBuilder))] | ||
|
||
namespace Orleans.Hosting; | ||
|
||
internal sealed class DynamoDBRemindersProviderBuilder : IProviderBuilder<ISiloBuilder> | ||
{ | ||
public void Configure(ISiloBuilder builder, string name, IConfigurationSection configurationSection) | ||
{ | ||
builder.UseDynamoDBReminderService(options => | ||
{ | ||
var accessKey = configurationSection[nameof(options.AccessKey)]; | ||
if (!string.IsNullOrEmpty(accessKey)) | ||
{ | ||
options.AccessKey = accessKey; | ||
} | ||
var secretKey = configurationSection[nameof(options.SecretKey)]; | ||
if (!string.IsNullOrEmpty(secretKey)) | ||
{ | ||
options.SecretKey = secretKey; | ||
} | ||
var region = configurationSection[nameof(options.Service)] ?? configurationSection["Region"]; | ||
if (!string.IsNullOrEmpty(region)) | ||
{ | ||
options.Service = region; | ||
} | ||
var token = configurationSection[nameof(options.SecretKey)]; | ||
if (!string.IsNullOrEmpty(token)) | ||
{ | ||
options.Token = token; | ||
} | ||
var profileName = configurationSection[nameof(options.SecretKey)]; | ||
if (!string.IsNullOrEmpty(profileName)) | ||
{ | ||
options.ProfileName = profileName; | ||
} | ||
var tableName = configurationSection[nameof(options.TableName)]; | ||
if (!string.IsNullOrEmpty(tableName)) | ||
{ | ||
options.TableName = tableName; | ||
} | ||
if (int.TryParse(configurationSection[nameof(options.ReadCapacityUnits)], out var rcu)) | ||
{ | ||
options.ReadCapacityUnits = rcu; | ||
} | ||
if (int.TryParse(configurationSection[nameof(options.WriteCapacityUnits)], out var wcu)) | ||
{ | ||
options.WriteCapacityUnits = wcu; | ||
} | ||
if (bool.TryParse(configurationSection[nameof(options.UseProvisionedThroughput)], out var upt)) | ||
{ | ||
options.UseProvisionedThroughput = upt; | ||
} | ||
if (bool.TryParse(configurationSection[nameof(options.CreateIfNotExists)], out var cine)) | ||
{ | ||
options.CreateIfNotExists = cine; | ||
} | ||
if (bool.TryParse(configurationSection[nameof(options.UpdateIfExists)], out var uie)) | ||
{ | ||
options.UpdateIfExists = uie; | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.