@@ -68,6 +68,54 @@ public async Task StartupStaticCtorThrows_Fallback(IWebHostBuilder builder)
68
68
}
69
69
}
70
70
71
+ [ Theory ]
72
+ [ MemberData ( nameof ( DefaultWebHostBuildersWithConfig ) ) ]
73
+ public async Task MultipleUseStartupCallsLastWins ( IWebHostBuilder builder )
74
+ {
75
+ var server = new TestServer ( ) ;
76
+ var host = builder . UseServer ( server )
77
+ . UseStartup < StartupCtorThrows > ( )
78
+ . UseStartup ( context => throw new InvalidOperationException ( "This doesn't run" ) )
79
+ . Configure ( app =>
80
+ {
81
+ throw new InvalidOperationException ( "This doesn't run" ) ;
82
+ } )
83
+ . Configure ( app =>
84
+ {
85
+ app . Run ( context =>
86
+ {
87
+ return context . Response . WriteAsync ( "This wins" ) ;
88
+ } ) ;
89
+ } )
90
+ . Build ( ) ;
91
+ using ( host )
92
+ {
93
+ await host . StartAsync ( ) ;
94
+ await AssertResponseContains ( server . RequestDelegate , "This wins" ) ;
95
+ }
96
+ }
97
+
98
+ [ Theory ]
99
+ [ MemberData ( nameof ( DefaultWebHostBuildersWithConfig ) ) ]
100
+ public async Task UseStartupFactoryWorks ( IWebHostBuilder builder )
101
+ {
102
+ void ConfigureServices ( IServiceCollection services ) { }
103
+ void Configure ( IApplicationBuilder app )
104
+ {
105
+ app . Run ( context => context . Response . WriteAsync ( "UseStartupFactoryWorks" ) ) ;
106
+ }
107
+
108
+ var server = new TestServer ( ) ;
109
+ var host = builder . UseServer ( server )
110
+ . UseStartup ( context => new DelegatingStartup ( ConfigureServices , Configure ) )
111
+ . Build ( ) ;
112
+ using ( host )
113
+ {
114
+ await host . StartAsync ( ) ;
115
+ await AssertResponseContains ( server . RequestDelegate , "UseStartupFactoryWorks" ) ;
116
+ }
117
+ }
118
+
71
119
[ Theory ]
72
120
[ MemberData ( nameof ( DefaultWebHostBuildersWithConfig ) ) ]
73
121
public async Task StartupCtorThrows_Fallback ( IWebHostBuilder builder )
@@ -199,7 +247,7 @@ public void ConfigureDefaultServiceProviderWithContext(IWebHostBuilder builder)
199
247
options . ValidateScopes = true ;
200
248
} ) ;
201
249
202
- using var host = hostBuilder . Build ( ) ;
250
+ using var host = hostBuilder . Build ( ) ;
203
251
Assert . Throws < InvalidOperationException > ( ( ) => host . Start ( ) ) ;
204
252
Assert . True ( configurationCallbackCalled ) ;
205
253
}
@@ -1218,7 +1266,7 @@ public void UseConfigurationWithSectionAddsSubKeys(IWebHostBuilder builder)
1218
1266
1219
1267
Assert . Equal ( "nestedvalue" , builder . GetSetting ( "key" ) ) ;
1220
1268
1221
- using var host = builder . Build ( ) ;
1269
+ using var host = builder . Build ( ) ;
1222
1270
var appConfig = host . Services . GetRequiredService < IConfiguration > ( ) ;
1223
1271
Assert . Equal ( "nestedvalue" , appConfig [ "key" ] ) ;
1224
1272
}
@@ -1574,6 +1622,21 @@ public void Configure(IWebHostBuilder builder)
1574
1622
}
1575
1623
}
1576
1624
1625
+ public class DelegatingStartup
1626
+ {
1627
+ private readonly Action < IServiceCollection > _configureServices ;
1628
+ private readonly Action < IApplicationBuilder > _configure ;
1629
+
1630
+ public DelegatingStartup ( Action < IServiceCollection > configureServices , Action < IApplicationBuilder > configure )
1631
+ {
1632
+ _configureServices = configureServices ;
1633
+ _configure = configure ;
1634
+ }
1635
+
1636
+ public void ConfigureServices ( IServiceCollection services ) => _configureServices ( services ) ;
1637
+ public void Configure ( IApplicationBuilder app ) => _configure ( app ) ;
1638
+ }
1639
+
1577
1640
public class StartupWithResolvedDisposableThatThrows
1578
1641
{
1579
1642
public StartupWithResolvedDisposableThatThrows ( DisposableService service )
0 commit comments