-
Notifications
You must be signed in to change notification settings - Fork 0
/
IHostBuilderExtensions.cs
43 lines (41 loc) · 1.31 KB
/
IHostBuilderExtensions.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
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Gradient.BuilderExtensions
{
/// <summary>
/// Helper extensions for building the app
/// </summary>
public static class IHostBuilderExtensions
{
/// <summary>
/// Add standard configuration options
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public static IHostBuilder BuildConfiguration(this IHostBuilder builder)
{
builder.ConfigureAppConfiguration(app =>
{
app.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
app.AddEnvironmentVariables();
});
return builder;
}
/// <summary>
/// Add a singleton to the services
/// </summary>
/// <typeparam name="TService"></typeparam>
/// <param name="builder"></param>
/// <returns></returns>
public static IHostBuilder AddService<TService>(this IHostBuilder builder)
where TService : class
{
builder.ConfigureServices(services =>
{
services.AddSingleton<TService>();
});
return builder;
}
}
}