1
- using Microsoft . AspNetCore . Hosting ;
1
+ using Blazored . Toast ;
2
+ using LinkDotNet . Blog . Web . Authentication . Auth0 ;
3
+ using LinkDotNet . Blog . Web . Authentication . Dummy ;
4
+ using LinkDotNet . Blog . Web . RegistrationExtensions ;
5
+ using Microsoft . AspNetCore . Builder ;
6
+ using Microsoft . Extensions . DependencyInjection ;
2
7
using Microsoft . Extensions . Hosting ;
3
8
4
9
namespace LinkDotNet . Blog . Web ;
@@ -7,10 +12,56 @@ public static class Program
7
12
{
8
13
public static void Main ( string [ ] args )
9
14
{
10
- CreateHostBuilder ( args ) . Build ( ) . Run ( ) ;
15
+ var builder = WebApplication . CreateBuilder ( args ) ;
16
+ RegisterServices ( builder ) ;
17
+
18
+ var app = builder . Build ( ) ;
19
+ ConfigureApp ( app ) ;
20
+
21
+ app . Run ( ) ;
22
+ }
23
+
24
+ private static void RegisterServices ( WebApplicationBuilder builder )
25
+ {
26
+ builder . Services . AddRazorPages ( ) ;
27
+ builder . Services . AddServerSideBlazor ( ) ;
28
+ builder . Services . AddSingleton ( _ => AppConfigurationFactory . Create ( builder . Configuration ) ) ;
29
+ builder . Services . AddBlazoredToast ( ) ;
30
+ builder . Services . RegisterServices ( ) ;
31
+ builder . Services . AddStorageProvider ( builder . Configuration ) ;
32
+
33
+ if ( builder . Environment . IsDevelopment ( ) )
34
+ {
35
+ builder . Services . UseDummyAuthentication ( ) ;
36
+ }
37
+ else
38
+ {
39
+ builder . Services . UseAuth0Authentication ( builder . Configuration ) ;
40
+ }
11
41
}
12
42
13
- public static IHostBuilder CreateHostBuilder ( string [ ] args ) =>
14
- Host . CreateDefaultBuilder ( args )
15
- . ConfigureWebHostDefaults ( webBuilder => { webBuilder . UseStartup < Startup > ( ) ; } ) ;
43
+ private static void ConfigureApp ( WebApplication app )
44
+ {
45
+ if ( app . Environment . IsDevelopment ( ) )
46
+ {
47
+ app . UseDeveloperExceptionPage ( ) ;
48
+ }
49
+ else
50
+ {
51
+ app . UseExceptionHandler ( "/Error" ) ;
52
+ app . UseHsts ( ) ;
53
+ }
54
+
55
+ app . UseHttpsRedirection ( ) ;
56
+ app . UseStaticFiles ( ) ;
57
+
58
+ app . UseRouting ( ) ;
59
+
60
+ app . UseCookiePolicy ( ) ;
61
+ app . UseAuthentication ( ) ;
62
+ app . UseAuthorization ( ) ;
63
+
64
+ app . MapBlazorHub ( ) ;
65
+ app . MapFallbackToPage ( "/_Host" ) ;
66
+ }
16
67
}
0 commit comments