-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
50 lines (44 loc) · 1.58 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
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Ghost;
namespace BlazorGhost
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
);
});
/// create regular scoped HttpClient
builder.Services.AddScoped(client => new HttpClient {
BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
});
/// create singleton GhostService
/// singleton needed for data caching to work
builder.Services.AddSingleton<GhostService>(service => new CachedGhostService(
new HttpClient {
BaseAddress = new Uri(GhostSettings.RestApiLocation)
}));
var host = builder.Build();
var ghostService = host.Services.GetRequiredService<GhostService>();
await host.RunAsync();
}
}
}