-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathRegistryGrain.cs
30 lines (28 loc) · 959 Bytes
/
RegistryGrain.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
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Orleans;
using Orleans.Providers;
using Patterns.Registry.Interface;
namespace Patterns.Registry.Implementation
{
[StorageProvider(ProviderName = "RegistryStore")]
public abstract class RegistryGrain<TRegisteredGrain> : Grain<RegistryState<TRegisteredGrain>>,
IRegistryGrain<TRegisteredGrain> where TRegisteredGrain : IGrain
{
public Task<List<TRegisteredGrain>> GetRegisteredGrains()
{
return Task.FromResult(State.RegisteredGrains.ToList());
}
public async Task<TRegisteredGrain> RegisterGrain(TRegisteredGrain item)
{
if (State.RegisteredGrains == null)
{
State.RegisteredGrains = new HashSet<TRegisteredGrain>();
}
State.RegisteredGrains.Add(item);
await WriteStateAsync();
return item;
}
}
}