-
Notifications
You must be signed in to change notification settings - Fork 2k
/
HostingGrainExtensions.cs
37 lines (35 loc) · 1.95 KB
/
HostingGrainExtensions.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
using Orleans.CodeGeneration;
using Orleans.Runtime;
namespace Orleans.Hosting
{
/// <summary>
/// Methods for configuring <see cref="IGrainExtension"/>s on a silo.
/// </summary>
public static class HostingGrainExtensions
{
/// <summary>
/// Registers a grain extension implementation for the specified interface.
/// </summary>
/// <typeparam name="TExtensionInterface">The <see cref="IGrainExtension"/> interface being registered.</typeparam>
/// <typeparam name="TExtension">The implementation of <typeparamref name="TExtensionInterface"/>.</typeparam>
public static ISiloHostBuilder AddGrainExtension<TExtensionInterface, TExtension>(this ISiloHostBuilder builder)
where TExtensionInterface : class, IGrainExtension
where TExtension : class, TExtensionInterface
{
int interfaceId = GrainInterfaceUtils.GetGrainInterfaceId(typeof(TExtensionInterface));
return builder.ConfigureServices(services => services.AddTransientKeyedService<int, IGrainExtension, TExtension>(interfaceId));
}
/// <summary>
/// Registers a grain extension implementation for the specified interface.
/// </summary>
/// <typeparam name="TExtensionInterface">The <see cref="IGrainExtension"/> interface being registered.</typeparam>
/// <typeparam name="TExtension">The implementation of <typeparamref name="TExtensionInterface"/>.</typeparam>
public static ISiloBuilder AddGrainExtension<TExtensionInterface, TExtension>(this ISiloBuilder builder)
where TExtensionInterface : class, IGrainExtension
where TExtension : class, TExtensionInterface
{
int interfaceId = GrainInterfaceUtils.GetGrainInterfaceId(typeof(TExtensionInterface));
return builder.ConfigureServices(services => services.AddTransientKeyedService<int, IGrainExtension, TExtension>(interfaceId));
}
}
}