22using Microsoft . Extensions . Configuration ;
33using Microsoft . Extensions . DependencyInjection ;
44using Microsoft . Extensions . Hosting ;
5+ using Microsoft . Extensions . Options ;
56using Stack_Solver . Data ;
67using Stack_Solver . Data . Repositories ;
8+ using Stack_Solver . Infrastructure ;
9+ using Stack_Solver . Models ;
710using Stack_Solver . Services ;
811using Stack_Solver . ViewModels . Pages ;
912using Stack_Solver . ViewModels . Windows ;
@@ -28,7 +31,11 @@ public partial class App
2831 // https://docs.microsoft.com/dotnet/core/extensions/logging
2932 private static readonly IHost _host = Host
3033 . CreateDefaultBuilder ( )
31- . ConfigureAppConfiguration ( c => { c . SetBasePath ( Path . GetDirectoryName ( AppContext . BaseDirectory ) ) ; } )
34+ . ConfigureAppConfiguration ( c =>
35+ {
36+ c . SetBasePath ( Path . GetDirectoryName ( AppContext . BaseDirectory ) ! ) ;
37+ c . AddJsonFile ( "defaults.json" , optional : true , reloadOnChange : true ) ;
38+ } )
3239 . ConfigureServices ( ( context , services ) =>
3340 {
3441 services . AddNavigationViewPageProvider ( ) ;
@@ -55,22 +62,31 @@ public partial class App
5562 services . AddSingleton < SKULibraryPage > ( ) ;
5663 services . AddSingleton < SKULibraryViewModel > ( ) ;
5764 services . AddSingleton < PalletBuilderPage > ( ) ;
58- services . AddSingleton < PalletBuilderViewModel > ( ) ;
65+ services . AddSingleton < PalletBuilderViewModel > ( sp => new PalletBuilderViewModel (
66+ sp . GetRequiredService < ISkuRepository > ( ) ,
67+ sp . GetRequiredService < IEventAggregator > ( ) ,
68+ sp . GetRequiredService < ILayerVisualizationService > ( ) ,
69+ sp . GetRequiredService < IOptions < GenerationOptions > > ( ) ,
70+ sp . GetRequiredService < IOptions < PalletDefaultsOptions > > ( ) ) ) ;
5971 services . AddSingleton < TruckLoadingPage > ( ) ;
6072 services . AddSingleton < TruckLoadingViewModel > ( ) ;
6173 services . AddSingleton < JobManagerPage > ( ) ;
6274 services . AddSingleton < JobManagerViewModel > ( ) ;
6375
76+ services . AddSingleton < IEventAggregator , EventAggregator > ( ) ;
77+ services . AddSingleton < ILayerVisualizationService , LayerVisualizationService > ( ) ;
78+
6479 services . AddDbContextFactory < ApplicationDbContext > ( options =>
6580 {
6681 options . UseSqlite ( $ "Data Source={ AppPaths . DatabaseFile } ") ;
6782 } ) ;
6883
69- // Repositories
7084 services . AddSingleton < ISkuRepository , SkuRepository > ( ) ;
71-
72- // Initializer
7385 services . AddSingleton < DatabaseInitializer > ( ) ;
86+
87+ // Bind options from host configuration
88+ services . Configure < GenerationOptions > ( context . Configuration . GetSection ( "LayerGeneration" ) ) ;
89+ services . Configure < PalletDefaultsOptions > ( context . Configuration . GetSection ( "PalletDefaults" ) ) ;
7490 } ) . Build ( ) ;
7591
7692 /// <summary>
0 commit comments