This repository has been archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 310
/
StartupInjection.cs
69 lines (61 loc) · 2.04 KB
/
StartupInjection.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
// HostingStartup's in the primary assembly are run automatically.
[assembly: HostingStartup(typeof(SampleStartups.StartupInjection))]
namespace SampleStartups
{
public class StartupInjection : IHostingStartup
{
public void Configure(IWebHostBuilder builder)
{
builder.UseStartup<InjectedStartup>();
}
// Entry point for the application.
public static void Main(string[] args)
{
var host = new WebHostBuilder()
//.UseKestrel()
.UseFakeServer()
// Each of these three sets ApplicationName to the current assembly, which is needed in order to
// scan the assembly for HostingStartupAttributes.
// .UseSetting(WebHostDefaults.ApplicationKey, "SampleStartups")
// .Configure(_ => { })
.UseStartup<NormalStartup>()
.Build();
host.Run();
}
}
public class NormalStartup
{
public void ConfigureServices(IServiceCollection services)
{
Console.WriteLine("NormalStartup.ConfigureServices");
}
public void Configure(IApplicationBuilder app)
{
Console.WriteLine("NormalStartup.Configure");
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
}
public class InjectedStartup
{
public void ConfigureServices(IServiceCollection services)
{
Console.WriteLine("InjectedStartup.ConfigureServices");
}
public void Configure(IApplicationBuilder app)
{
Console.WriteLine("InjectedStartup.Configure");
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
}
}