-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
101 lines (85 loc) · 2.82 KB
/
Program.cs
File metadata and controls
101 lines (85 loc) · 2.82 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
using Faucet;
using Faucet.Cryptography;
using Faucet.Data;
using Faucet.Extensions;
using Faucet.Hubs;
using Faucet.Ledger;
using Faucet.Persistence;
using Faucet.Services;
using Faucet.Wallet;
using Microsoft.AspNetCore.ResponseCompression;
using Serilog;
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json"), false, true)
.AddCommandLine(args)
.Build();
const string logSectionName = "Log";
if (config.GetSection(logSectionName) != null)
{
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(config, logSectionName)
.CreateLogger();
}
else
{
throw new Exception($"No \"{logSectionName}\" section found in appsettings.json");
}
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSignalR();
builder.Services.AddDataKeysProtection(config);
builder.Services.AddSingleton<IFaucetSystem, FaucetSystem>();
builder.Services.AddSingleton<IUnitOfWork>(sp =>
{
var unitOfWork = new UnitOfWork("storedb", Log.Logger);
return unitOfWork;
});
builder.Services.AddSingleton<IWalletSession, WalletSession>();
builder.Services.AddSingleton<IBlockchain, Blockchain>();
builder.Services.AddTransient<ICrypto, Crypto>();
builder.Services.AddTransient<IWallet, Wallet>();
builder.Services.AddSingleton(sp =>
{
var url = config?["HttpEndPoint"];
var dataServices = new DataService(sp.GetService<IHostApplicationLifetime>(), sp.GetService<IHttpClientFactory>(), url, Log.Logger);
return dataServices;
});
builder.Services.AddSingleton<IBackgroundWorkerQueue, BackgroundWorkerQueue>();
builder.Services.AddSingleton(Log.Logger);
builder.Services.AddHostedService<LongRunningService>();
builder.Services.AddHttpClient();
builder.Services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSerilog();
});
builder.Logging.AddSerilog();
//builder.Services.AddLettuceEncrypt();
var app = builder.Build();
app.Lifetime.ApplicationStarted.Register(() =>
{
app.Services.GetService<IUnitOfWork>();
app.Services.GetService<IWalletSession>();
app.Services.GetService<IBlockchain>();
});
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.MapControllers();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
//endpoints.MapFallbackToPage("/_Host");
endpoints.MapHub<MinerHub>("/blockminer");
});
Console.WriteLine($"Process ID:{Environment.ProcessId}");
app.Run();