-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartup.cs
More file actions
55 lines (49 loc) · 1.84 KB
/
Startup.cs
File metadata and controls
55 lines (49 loc) · 1.84 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
namespace Neolution.DotNet.Console.Demo
{
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
/// <summary>
/// The startup class, composition root for the application.
/// </summary>
internal class Startup
{
/// <summary>
/// Initializes a new instance of the <see cref="Startup" /> class.
/// </summary>
/// <param name="environment">The environment.</param>
/// <param name="configuration">The configuration.</param>
public Startup(IHostEnvironment environment, IConfiguration configuration)
{
this.Environment = environment;
this.Configuration = configuration;
}
/// <summary>
/// Gets the environment.
/// </summary>
public IHostEnvironment Environment { get; }
/// <summary>
/// Gets the configuration.
/// </summary>
public IConfiguration Configuration { get; }
/// <summary>
/// Configures the services.
/// </summary>
/// <remarks>This method gets called by the runtime. Use this method to add services to the container.</remarks>
/// <param name="services">The services.</param>
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient();
// EXAMPLE 1: Configure services based on the environment
if (this.Environment.IsDevelopment())
{
// Register services only used in development
}
// EXAMPLE 2: Configure services based on the configurations
if (this.Configuration.GetValue<bool>("NLog:throwConfigExceptions"))
{
// Do something based on a configuration value
}
}
}
}