3
3
using System . Threading . Tasks ;
4
4
using Microsoft . AspNetCore . Builder ;
5
5
using Microsoft . AspNetCore . Hosting ;
6
+ using Microsoft . AspNetCore . Http ;
7
+ using Microsoft . Extensions . DependencyInjection ;
6
8
using Microsoft . Extensions . Hosting ;
7
9
8
10
namespace AspNetCoreAPIExample
@@ -14,14 +16,39 @@ public class LocalEntryPoint
14
16
{
15
17
public static void Main ( string [ ] args )
16
18
{
17
- CreateHostBuilder ( args ) . Build ( ) . Run ( ) ;
19
+ CreateHostBuilder ( args ) . Run ( ) ;
18
20
}
19
21
20
- public static WebApplicationBuilder CreateHostBuilder ( string [ ] args )
22
+ public static WebApplication CreateHostBuilder ( string [ ] args )
21
23
{
22
24
var builder = WebApplication . CreateBuilder ( args ) ;
23
- builder . WebHost . UseStartup < Startup > ( ) ;
24
- return builder ;
25
+
26
+ builder . Services . AddScoped < IFakeDependency , FakeDependency > ( ) ;
27
+ builder . Services . AddControllers ( ) ;
28
+
29
+ var app = builder . Build ( ) ;
30
+
31
+ if ( app . Environment . IsDevelopment ( ) )
32
+ {
33
+ app . UseDeveloperExceptionPage ( ) ;
34
+ }
35
+
36
+ app . UseHttpsRedirection ( ) ;
37
+
38
+ app . UseRouting ( ) ;
39
+
40
+ app . UseAuthorization ( ) ;
41
+
42
+ app . UseEndpoints ( endpoints =>
43
+ {
44
+ endpoints . MapControllers ( ) ;
45
+ endpoints . MapGet ( "/" , async context =>
46
+ {
47
+ await context . Response . WriteAsync ( "Welcome to running ASP.NET Core on AWS Lambda" ) ;
48
+ } ) ;
49
+ } ) ;
50
+
51
+ return app ;
25
52
}
26
53
}
27
54
}
0 commit comments