@@ -945,6 +945,54 @@ public void Build_ConfigureAppConfigurationInHostingStartupWorks(IWebHostBuilder
945
945
}
946
946
}
947
947
948
+ [ Theory ]
949
+ [ MemberData ( nameof ( DefaultWebHostBuildersWithConfig ) ) ]
950
+ public void Build_AppConfigAvailableEverywhere ( IWebHostBuilder builder )
951
+ {
952
+ builder = builder
953
+ . CaptureStartupErrors ( false )
954
+ . ConfigureAppConfiguration ( ( context , configurationBuilder ) => {
955
+ configurationBuilder . AddInMemoryCollection (
956
+ new [ ]
957
+ {
958
+ new KeyValuePair < string , string > ( "appconfig" , "appvalue" )
959
+ } ) ;
960
+ } )
961
+ . ConfigureLogging ( ( context , logging ) =>
962
+ {
963
+ Assert . Equal ( "appvalue" , context . Configuration [ "appconfig" ] ) ;
964
+ } )
965
+ . ConfigureServices ( ( context , services ) =>
966
+ {
967
+ Assert . Equal ( "appvalue" , context . Configuration [ "appconfig" ] ) ;
968
+ } )
969
+ . UseDefaultServiceProvider ( ( context , services ) =>
970
+ {
971
+ Assert . Equal ( "appvalue" , context . Configuration [ "appconfig" ] ) ;
972
+ } )
973
+ . UseStartup < StartupCheckConfig > ( )
974
+ . UseServer ( new TestServer ( ) ) ;
975
+
976
+ using ( var host = builder . Build ( ) )
977
+ {
978
+ var configuration = host . Services . GetRequiredService < IConfiguration > ( ) ;
979
+ Assert . Equal ( "appvalue" , configuration [ "appconfig" ] ) ;
980
+ }
981
+ }
982
+
983
+ public class StartupCheckConfig
984
+ {
985
+ public StartupCheckConfig ( IConfiguration config )
986
+ {
987
+ Assert . Equal ( "value" , config [ "testhostingstartup:config" ] ) ;
988
+ }
989
+
990
+ public void Configure ( IApplicationBuilder app )
991
+ {
992
+
993
+ }
994
+ }
995
+
948
996
[ Theory ]
949
997
[ MemberData ( nameof ( DefaultWebHostBuildersWithConfig ) ) ]
950
998
public void Build_DoesRunHostingStartupFromPrimaryAssemblyEvenIfNotSpecified ( IWebHostBuilder builder )
0 commit comments