forked from llebj/orleans-on-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
57 lines (51 loc) · 2.21 KB
/
Program.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
using Client;
using Client.Extensions;
using Client.Options;
using Client.Services;
using GrainInterfaces;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
using Shared;
using Shared.Extensions;
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.Build();
var logger = new LoggerConfiguration()
.ReadFrom
.Configuration(configuration)
.CreateLogger();
var builder = Host.CreateDefaultBuilder(args)
.UseOrleansClient(client =>
{
client.ConfigureClustering(configuration);
// A System.Text.Json serializer has to be used here as I was unable to get the orleans serialization to work.
// I attempted to use the GenerateSerializerAttribute coupled with IdAttribute, however the code generator
// was unable to find the copier as the ChatMessage class resides in a different assembly.
// I then tried using the GenerateCodeForDeclaringAssembly to generate for ChatMessage, but that required
// public setters even though I declared the type as being Immutable and even then, it couldn't locate the
// copier.
client.Services.AddJsonSerializerForAssembly(typeof(ChatMessage));
})
.ConfigureServices(serviceCollection =>
{
serviceCollection.Configure<ObserverManagerOptions>(configuration.GetSection(ObserverManagerOptions.Key));
serviceCollection.AddScoped<IChatObserver, ChatObserver>();
serviceCollection.AddScoped<IChatService, ChatService>();
serviceCollection.AddScoped<ISubscriptionManager, GrainObserverManager>();
serviceCollection.AddScoped<IMessageStream, MessageStream>();
serviceCollection.AddScoped<IResubscriber<GrainSubscription>, ResubscriptionTimer<GrainSubscription>>();
serviceCollection.AddSingleton(TimeProvider.System);
serviceCollection.AddHostedService<ChatHostedService>();
})
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.AddSerilog(logger);
})
.UseConsoleLifetime();
using IHost host = builder.Build();
await host.RunAsync();