blob: 4d02d0d815e99921bc6108becc02c08aaf33e230 (
plain)
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
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace RoutingSandbox
{
public class Program
{
public const string EndpointRoutingScenario = "endpointrouting";
public const string RouterScenario = "router";
public static Task Main(string[] args)
{
var host = GetHostBuilder(args).Build();
return host.RunAsync();
}
// For unit testing
public static IHostBuilder GetHostBuilder(string[] args)
{
string scenario;
if (args.Length == 0)
{
Console.WriteLine("Choose a sample to run:");
Console.WriteLine($"1. {EndpointRoutingScenario}");
Console.WriteLine($"2. {RouterScenario}");
Console.WriteLine();
scenario = Console.ReadLine();
}
else
{
scenario = args[0];
}
Type startupType;
switch (scenario)
{
case "1":
case EndpointRoutingScenario:
startupType = typeof(UseEndpointRoutingStartup);
break;
case "2":
case RouterScenario:
startupType = typeof(UseRouterStartup);
break;
default:
Console.WriteLine($"unknown scenario {scenario}");
Console.WriteLine($"usage: dotnet run -- ({EndpointRoutingScenario}|{RouterScenario})");
throw new InvalidOperationException();
}
return new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseKestrel()
.UseIISIntegration()
.UseContentRoot(Environment.CurrentDirectory)
.UseStartup(startupType);
})
.ConfigureLogging(b =>
{
b.AddConsole();
b.SetMinimumLevel(LogLevel.Critical);
});
}
}
}
|