-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRealHostBuilder.cs
More file actions
107 lines (82 loc) · 3.62 KB
/
RealHostBuilder.cs
File metadata and controls
107 lines (82 loc) · 3.62 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System.Linq;
using System.Net;
using System.Net.Sockets;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Orleans;
using Orleans.Configuration;
using Orleans.Hosting;
using Serilog;
using System.IO;
using System;
using Microsoft.AspNetCore.Hosting;
using Test.Host.Api;
using Test.Common.Constants;
namespace Test.Host
{
public static class RealHostBuilder
{
public static IHostBuilder GetHost(string[] args, IConfigurationRoot config, ILogger hostLogger)
{
if (config == null)
throw new ArgumentNullException(nameof(config));
if (hostLogger == null)
throw new ArgumentNullException(nameof(hostLogger));
hostLogger.Information($"--------- Building Host ---------");
// Need this for it to work with Docker.
var name = Dns.GetHostName(); // get container id
var ip = Dns.GetHostEntry(name).AddressList.FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork);
return new HostBuilder()
.ConfigureAppConfiguration((hostContext, configApp) =>
{
configApp.SetBasePath(Directory.GetCurrentDirectory());
configApp.AddJsonFile("appsettings.json", optional: true);
configApp.AddJsonFile(
$"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json",
optional: true);
configApp.AddEnvironmentVariables();
configApp.AddCommandLine(args);
})
.ConfigureServices(services =>
{
services.AddMemoryCache();
services.AddHttpClient();
services.Configure<ConsoleLifetimeOptions>(options =>
{
options.SuppressStatusMessages = true;
});
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.UseOrleans(builder =>
{
builder
.Configure<SiloOptions>(options =>
{
options.SiloName = Dns.GetHostName();
})
.Configure<ClusterOptions>(options =>
{
options.ClusterId = "MyClusterId";
options.ServiceId = "MyCluster";
})
// .ConfigureEndpoints(siloPort: hostOptions.OrleansSiloPort, gatewayPort: hostOptions.OrleansGatewayPort)
.Configure<EndpointOptions>(options =>
{
options.AdvertisedIPAddress = ip;
})
.UseLocalhostClustering()
.UseInMemoryReminderService()
.AddSimpleMessageStreamProvider(HostConstants.STREAM_PROVIDER, opt => opt.FireAndForgetDelivery = true)
.AddMemoryGrainStorage("PubSubStore")
.AddStartupTask<CallGrainStartupTask>();
hostLogger.Information("Adding Orleans dashboard");
builder.UseDashboard(options => { });
});
}
}
}