@@ -7,6 +7,7 @@ namespace Atc.Wpf.Sample;
7
7
public partial class App
8
8
{
9
9
private readonly IHost host ;
10
+ private IConfiguration ? configuration ;
10
11
11
12
public App ( )
12
13
{
@@ -17,8 +18,22 @@ public App()
17
18
. AddDebug ( )
18
19
. SetMinimumLevel ( LogLevel . Trace ) ;
19
20
} )
21
+ . ConfigureAppConfiguration ( ( _ , configurationBuilder ) =>
22
+ {
23
+ configuration = configurationBuilder . SetBasePath ( Directory . GetCurrentDirectory ( ) )
24
+ . AddJsonFile ( AtcFileNameConstants . AppSettings , optional : false , reloadOnChange : true )
25
+ . AddJsonFile ( AtcFileNameConstants . AppSettingsCustom , optional : true , reloadOnChange : true )
26
+ . AddEnvironmentVariables ( )
27
+ . Build ( ) ;
28
+ } )
20
29
. ConfigureServices ( ( _ , services ) =>
21
30
{
31
+ services
32
+ . AddOptions < BasicApplicationOptions > ( )
33
+ . Bind ( configuration ! . GetRequiredSection ( BasicApplicationOptions . SectionName ) )
34
+ . ValidateDataAnnotations ( )
35
+ . ValidateOnStart ( ) ;
36
+
22
37
services . AddSingleton < IMainWindowViewModel , MainWindowViewModel > ( ) ;
23
38
services . AddSingleton < MainWindow > ( ) ;
24
39
} )
@@ -103,17 +118,18 @@ await host
103
118
. StartAsync ( )
104
119
. ConfigureAwait ( false ) ;
105
120
106
- CultureManager . SetCultures (
107
- GlobalizationConstants . EnglishCultureInfo ,
108
- GlobalizationConstants . EnglishCultureInfo ) ;
121
+ var applicationOptions = new BasicApplicationOptions ( ) ;
122
+ configuration !
123
+ . GetRequiredSection ( BasicApplicationOptions . SectionName )
124
+ . Bind ( applicationOptions ) ;
125
+
126
+ CultureManager . SetCultures ( applicationOptions . Language ) ;
127
+
128
+ ThemeManagerHelper . SetThemeAndAccent ( Current , applicationOptions . Theme ) ;
109
129
110
130
ColorHelper . InitializeWithSupportedLanguages ( ) ;
111
131
SolidColorBrushHelper . InitializeWithSupportedLanguages ( ) ;
112
132
113
- ThemeManager . Current . ChangeTheme (
114
- Current ,
115
- "Light.Blue" ) ;
116
-
117
133
var mainWindow = host
118
134
. Services
119
135
. GetService < MainWindow > ( ) ! ;
0 commit comments