-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathAzureTableSiloBuilderExtensions.cs
89 lines (80 loc) · 4.76 KB
/
AzureTableSiloBuilderExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using Orleans.Configuration;
using Orleans.Providers;
using Orleans.Runtime;
using Orleans.Storage;
namespace Orleans.Hosting
{
public static class AzureTableSiloBuilderExtensions
{
/// <summary>
/// Configure silo to use azure table storage as the default grain storage.
/// </summary>
public static ISiloHostBuilder AddAzureTableGrainStorageAsDefault(this ISiloHostBuilder builder, Action<AzureTableStorageOptions> configureOptions)
{
return builder.AddAzureTableGrainStorage(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME, configureOptions);
}
/// <summary>
/// Configure silo to use azure table storage for grain storage.
/// </summary>
public static ISiloHostBuilder AddAzureTableGrainStorage(this ISiloHostBuilder builder, string name, Action<AzureTableStorageOptions> configureOptions)
{
return builder.ConfigureServices(services => services.AddAzureTableGrainStorage(name, ob => ob.Configure(configureOptions)));
}
/// <summary>
/// Configure silo to use azure table storage as the default grain storage.
/// </summary>
public static ISiloHostBuilder AddAzureTableGrainStorageAsDefault(this ISiloHostBuilder builder, Action<OptionsBuilder<AzureTableStorageOptions>> configureOptions = null)
{
return builder.AddAzureTableGrainStorage(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME, configureOptions);
}
/// <summary>
/// Configure silo to use azure table storage for grain storage.
/// </summary>
public static ISiloHostBuilder AddAzureTableGrainStorage(this ISiloHostBuilder builder, string name, Action<OptionsBuilder<AzureTableStorageOptions>> configureOptions = null)
{
return builder.ConfigureServices(services => services.AddAzureTableGrainStorage(name, configureOptions));
}
/// <summary>
/// Configure silo to use azure table storage as the default grain storage.
/// </summary>
public static ISiloBuilder AddAzureTableGrainStorageAsDefault(this ISiloBuilder builder, Action<AzureTableStorageOptions> configureOptions)
{
return builder.AddAzureTableGrainStorage(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME, configureOptions);
}
/// <summary>
/// Configure silo to use azure table storage for grain storage.
/// </summary>
public static ISiloBuilder AddAzureTableGrainStorage(this ISiloBuilder builder, string name, Action<AzureTableStorageOptions> configureOptions)
{
return builder.ConfigureServices(services => services.AddAzureTableGrainStorage(name, ob => ob.Configure(configureOptions)));
}
/// <summary>
/// Configure silo to use azure table storage as the default grain storage.
/// </summary>
public static ISiloBuilder AddAzureTableGrainStorageAsDefault(this ISiloBuilder builder, Action<OptionsBuilder<AzureTableStorageOptions>> configureOptions = null)
{
return builder.AddAzureTableGrainStorage(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME, configureOptions);
}
/// <summary>
/// Configure silo to use azure table storage for grain storage.
/// </summary>
public static ISiloBuilder AddAzureTableGrainStorage(this ISiloBuilder builder, string name, Action<OptionsBuilder<AzureTableStorageOptions>> configureOptions = null)
{
return builder.ConfigureServices(services => services.AddAzureTableGrainStorage(name, configureOptions));
}
internal static IServiceCollection AddAzureTableGrainStorage(this IServiceCollection services, string name,
Action<OptionsBuilder<AzureTableStorageOptions>> configureOptions = null)
{
configureOptions?.Invoke(services.AddOptions<AzureTableStorageOptions>(name));
services.AddTransient<IConfigurationValidator>(sp => new AzureTableGrainStorageOptionsValidator(sp.GetRequiredService<IOptionsMonitor<AzureTableStorageOptions>>().Get(name), name));
services.ConfigureNamedOptionForLogging<AzureTableStorageOptions>(name);
services.TryAddSingleton<IGrainStorage>(sp => sp.GetServiceByName<IGrainStorage>(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME));
return services.AddSingletonNamedService<IGrainStorage>(name, AzureTableGrainStorageFactory.Create)
.AddSingletonNamedService<ILifecycleParticipant<ISiloLifecycle>>(name, (s, n) => (ILifecycleParticipant<ISiloLifecycle>)s.GetRequiredServiceByName<IGrainStorage>(n));
}
}
}