diff --git a/readme/Avalonia.md b/readme/Avalonia.md index 65f2ab0f5..5614c7566 100644 --- a/readme/Avalonia.md +++ b/readme/Avalonia.md @@ -50,6 +50,9 @@ A single instance of the _Composition_ class is defined as a static resource in ``` +
+Changes to App.axaml.cs are only needed if you want to add logic to dispose of resources. + The associated application [App.axaml.cs](/samples/AvaloniaApp/App.axaml.cs) class is looking like: ```c# @@ -73,6 +76,8 @@ public class App : Application } ``` +
+ All previously defined composition roots are now accessible from [markup](/samples/AvaloniaApp/Views/MainWindow.xaml) without any effort, such as _ClockViewModel_: ```xaml @@ -110,7 +115,7 @@ The [project file](/samples/AvaloniaApp/AvaloniaApp.csproj) looks like this: - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/AvaloniaPageTemplate.md b/readme/AvaloniaPageTemplate.md index 9c682ac87..b16c0353e 100644 --- a/readme/AvaloniaPageTemplate.md +++ b/readme/AvaloniaPageTemplate.md @@ -50,6 +50,9 @@ A single instance of the _Composition_ class is defined as a static resource in ``` +
+Changes to App.axaml.cs are only needed if you want to add logic to dispose of resources. + The associated application [App.axaml.cs](/samples/AvaloniaApp/App.axaml.cs) class is looking like: ```c# @@ -73,6 +76,8 @@ public class App : Application } ``` +
+ All previously defined composition roots are now accessible from [markup](/samples/AvaloniaApp/Views/MainWindow.xaml) without any effort, such as _ClockViewModel_: ```xaml diff --git a/readme/BlazorServerApp.md b/readme/BlazorServerApp.md index 5d856e45a..a6f1b29af 100644 --- a/readme/BlazorServerApp.md +++ b/readme/BlazorServerApp.md @@ -67,7 +67,7 @@ The [project file](/samples/BlazorServerApp/BlazorServerApp.csproj) looks like t - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/BlazorWebAssemblyApp.md b/readme/BlazorWebAssemblyApp.md index 678a85d62..872473e34 100644 --- a/readme/BlazorWebAssemblyApp.md +++ b/readme/BlazorWebAssemblyApp.md @@ -66,7 +66,7 @@ The [project file](/samples/BlazorWebAssemblyApp/BlazorWebAssemblyApp.csproj) lo - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/Console.md b/readme/Console.md index 6c257d11c..ac162e4e5 100644 --- a/readme/Console.md +++ b/readme/Console.md @@ -85,7 +85,7 @@ The [project file](/samples/ShroedingersCat/ShroedingersCat.csproj) looks like t - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/ConsoleNativeAOT.md b/readme/ConsoleNativeAOT.md index bd6aebd57..e1d5258b8 100644 --- a/readme/ConsoleNativeAOT.md +++ b/readme/ConsoleNativeAOT.md @@ -16,7 +16,7 @@ The [project file](/samples/ShroedingersCatNativeAOT/ShroedingersCatNativeAOT.cs - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/ConsoleTopLevelStatements.md b/readme/ConsoleTopLevelStatements.md index d7287f740..18002adfa 100644 --- a/readme/ConsoleTopLevelStatements.md +++ b/readme/ConsoleTopLevelStatements.md @@ -74,7 +74,7 @@ The [project file](/samples/ShroedingersCatTopLevelStatements/ShroedingersCatTop - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/GrpcService.md b/readme/GrpcService.md index d9c1fa985..e9298ecd5 100644 --- a/readme/GrpcService.md +++ b/readme/GrpcService.md @@ -52,7 +52,7 @@ The [project file](/samples/GrpcService/GrpcService.csproj) looks like this: - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/Maui.md b/readme/Maui.md index 34cc88907..70d789789 100644 --- a/readme/Maui.md +++ b/readme/Maui.md @@ -208,7 +208,7 @@ The [project file](/samples/MAUIApp/MAUIApp.csproj) looks like this: - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/MinimalWebAPI.md b/readme/MinimalWebAPI.md index bbc571f98..d0a3e759c 100644 --- a/readme/MinimalWebAPI.md +++ b/readme/MinimalWebAPI.md @@ -75,7 +75,7 @@ The [project file](/samples/WebAPI/WebAPI.csproj) looks like this: - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/WebAPI.md b/readme/WebAPI.md index ded418393..7db070c75 100644 --- a/readme/WebAPI.md +++ b/readme/WebAPI.md @@ -50,7 +50,7 @@ The [project file](/samples/WebAPI/WebAPI.csproj) looks like this: - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/WebApp.md b/readme/WebApp.md index 02ee0164e..530c5fb73 100644 --- a/readme/WebApp.md +++ b/readme/WebApp.md @@ -50,7 +50,7 @@ The [project file](/samples/WebApp/WebApp.csproj) looks like this: - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/WinFormsApp.md b/readme/WinFormsApp.md index 0be260b71..d304bc433 100644 --- a/readme/WinFormsApp.md +++ b/readme/WinFormsApp.md @@ -55,7 +55,7 @@ The [project file](/samples/WinFormsApp/WinFormsApp.csproj) looks like this: - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/WinFormsAppNetCore.md b/readme/WinFormsAppNetCore.md index e9d5f4190..5cd19c9be 100644 --- a/readme/WinFormsAppNetCore.md +++ b/readme/WinFormsAppNetCore.md @@ -62,7 +62,7 @@ The [project file](/samples/WinFormsAppNetCore/WinFormsAppNetCore.csproj) looks - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/Wpf.md b/readme/Wpf.md index 32cb43516..395980ee9 100644 --- a/readme/Wpf.md +++ b/readme/Wpf.md @@ -68,7 +68,7 @@ The [project file](/samples/WpfAppNetCore/WpfAppNetCore.csproj) looks like this: - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/bind-attribute-for-a-generic-type.md b/readme/bind-attribute-for-a-generic-type.md index 03fe27cf4..488bb215e 100644 --- a/readme/bind-attribute-for-a-generic-type.md +++ b/readme/bind-attribute-for-a-generic-type.md @@ -83,8 +83,8 @@ partial class Composition IDependency transientIDependency1; { - Facade localValue24 = _root._singletonFacade39!; - transientIDependency1 = localValue24.GetDependency(); + Facade localInstance_1182D12724 = _root._singletonFacade39!; + transientIDependency1 = localInstance_1182D12724.GetDependency(); } return new Service(transientIDependency1); diff --git a/readme/bind-attribute-with-lifetime-and-tag.md b/readme/bind-attribute-with-lifetime-and-tag.md index 3804ad465..50ff374f0 100644 --- a/readme/bind-attribute-with-lifetime-and-tag.md +++ b/readme/bind-attribute-with-lifetime-and-tag.md @@ -83,8 +83,8 @@ partial class Composition } { - Facade localValue26 = _root._singletonFacade39!; - _root._singletonIDependency0 = localValue26.Dependency; + Facade localInstance_1182D12726 = _root._singletonFacade39!; + _root._singletonIDependency0 = localInstance_1182D12726.Dependency; } } } diff --git a/readme/bind-attribute.md b/readme/bind-attribute.md index 298535986..12009b4c1 100644 --- a/readme/bind-attribute.md +++ b/readme/bind-attribute.md @@ -87,8 +87,8 @@ partial class Composition IDependency transientIDependency1; { - Facade localValue25 = _root._singletonFacade39!; - transientIDependency1 = localValue25.Dependency; + Facade localInstance_1182D12725 = _root._singletonFacade39!; + transientIDependency1 = localInstance_1182D12725.Dependency; } return new Service(transientIDependency1); diff --git a/readme/exposed-generic-roots-with-args.md b/readme/exposed-generic-roots-with-args.md index 7da7ce524..ec0442037 100644 --- a/readme/exposed-generic-roots-with-args.md +++ b/readme/exposed-generic-roots-with-args.md @@ -75,8 +75,8 @@ partial class Composition Integration.IMyGenericService transientIMyGenericService1; { int localId1 = id; - Integration.CompositionWithGenericRootsAndArgsInOtherProject localValue2 = _root._singletonCompositionWithGenericRootsAndArgsInOtherProject40!; - transientIMyGenericService1 = localValue2.GetMyService(localId1); + Integration.CompositionWithGenericRootsAndArgsInOtherProject localInstance_1182D1272 = _root._singletonCompositionWithGenericRootsAndArgsInOtherProject40!; + transientIMyGenericService1 = localInstance_1182D1272.GetMyService(localId1); } return new Program(transientIMyGenericService1); diff --git a/readme/exposed-generic-roots.md b/readme/exposed-generic-roots.md index fa37d4c84..a8265c66c 100644 --- a/readme/exposed-generic-roots.md +++ b/readme/exposed-generic-roots.md @@ -77,8 +77,8 @@ partial class Composition Integration.IMyGenericService transientIMyGenericService1; { - Integration.CompositionWithGenericRootsInOtherProject localValue0 = _root._singletonCompositionWithGenericRootsInOtherProject39!; - transientIMyGenericService1 = localValue0.GetMyService(); + Integration.CompositionWithGenericRootsInOtherProject localInstance_1182D1270 = _root._singletonCompositionWithGenericRootsInOtherProject39!; + transientIMyGenericService1 = localInstance_1182D1270.GetMyService(); } return new Program(transientIMyGenericService1); diff --git a/readme/exposed-roots-via-arg.md b/readme/exposed-roots-via-arg.md index 5aa25fe5f..db1b0ed15 100644 --- a/readme/exposed-roots-via-arg.md +++ b/readme/exposed-roots-via-arg.md @@ -61,8 +61,8 @@ partial class Composition { Integration.IMyService transientIMyService1; { - Integration.CompositionInOtherProject localValue4 = _argBaseComposition; - transientIMyService1 = localValue4.MyService; + Integration.CompositionInOtherProject localInstance_1182D1274 = _argBaseComposition; + transientIMyService1 = localInstance_1182D1274.MyService; } return new Program(transientIMyService1); diff --git a/readme/exposed-roots-via-root-arg.md b/readme/exposed-roots-via-root-arg.md index e778384da..5e5ddb977 100644 --- a/readme/exposed-roots-via-root-arg.md +++ b/readme/exposed-roots-via-root-arg.md @@ -56,8 +56,8 @@ partial class Composition { Integration.IMyService transientIMyService1; { - Integration.CompositionInOtherProject localValue5 = baseComposition; - transientIMyService1 = localValue5.MyService; + Integration.CompositionInOtherProject localInstance_1182D1275 = baseComposition; + transientIMyService1 = localInstance_1182D1275.MyService; } return new Program(transientIMyService1); diff --git a/readme/exposed-roots-with-tags.md b/readme/exposed-roots-with-tags.md index 1c40b5d94..cb1eb24b9 100644 --- a/readme/exposed-roots-with-tags.md +++ b/readme/exposed-roots-with-tags.md @@ -72,8 +72,8 @@ partial class Composition Integration.IMyService transientIMyService1; { - Integration.CompositionWithTagsInOtherProject localValue6 = _root._singletonCompositionWithTagsInOtherProject39!; - transientIMyService1 = localValue6.MyService; + Integration.CompositionWithTagsInOtherProject localInstance_1182D1276 = _root._singletonCompositionWithTagsInOtherProject39!; + transientIMyService1 = localInstance_1182D1276.MyService; } return new Program(transientIMyService1); diff --git a/readme/exposed-roots.md b/readme/exposed-roots.md index 881692d0e..c58d40fb9 100644 --- a/readme/exposed-roots.md +++ b/readme/exposed-roots.md @@ -75,8 +75,8 @@ partial class Composition Integration.IMyService transientIMyService1; { - Integration.CompositionInOtherProject localValue3 = _root._singletonCompositionInOtherProject39!; - transientIMyService1 = localValue3.MyService; + Integration.CompositionInOtherProject localInstance_1182D1273 = _root._singletonCompositionInOtherProject39!; + transientIMyService1 = localInstance_1182D1273.MyService; } return new Program(transientIMyService1); diff --git a/samples/SingleRootAvaloniaApp/App.axaml.cs b/samples/SingleRootAvaloniaApp/App.axaml.cs index 4cdfe7e89..c306902d4 100644 --- a/samples/SingleRootAvaloniaApp/App.axaml.cs +++ b/samples/SingleRootAvaloniaApp/App.axaml.cs @@ -14,7 +14,7 @@ public override void OnFrameworkInitializationCompleted() && Resources["Composition"] is Composition composition) { // Assignment of the main window - desktop.MainWindow = composition.App.MainWindow; + desktop.MainWindow = composition.Root.MainWindow.Value; // Handles disposables desktop.Exit += (_, _) => composition.Dispose(); } diff --git a/samples/SingleRootAvaloniaApp/AppDataContext.cs b/samples/SingleRootAvaloniaApp/AppDataContext.cs deleted file mode 100644 index 6c78f3270..000000000 --- a/samples/SingleRootAvaloniaApp/AppDataContext.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace AvaloniaApp; - -using Clock.ViewModels; -using Views; - -internal class AppDataContext( - Lazy mainWindow, - IClockViewModel clockViewModel) -{ - public MainWindow MainWindow => mainWindow.Value; - - public IClockViewModel ClockViewModel => clockViewModel; -} \ No newline at end of file diff --git a/samples/SingleRootAvaloniaApp/Composition.cs b/samples/SingleRootAvaloniaApp/Composition.cs index 382a69237..80633e2d0 100644 --- a/samples/SingleRootAvaloniaApp/Composition.cs +++ b/samples/SingleRootAvaloniaApp/Composition.cs @@ -7,15 +7,16 @@ namespace AvaloniaApp; using Clock.Models; using Clock.ViewModels; using Pure.DI; +using Views; using static Pure.DI.Lifetime; internal partial class Composition { void Setup() => DI.Setup() - // A single compositional root for the application - .Root(nameof(App)) + // Single composition root for the application + .Root(nameof(Root)) - .Bind().As(Singleton).To() + .Bind().As(Singleton).To() // View Models .Bind().To() diff --git a/samples/SingleRootAvaloniaApp/Root.cs b/samples/SingleRootAvaloniaApp/Root.cs new file mode 100644 index 000000000..7af65cbe8 --- /dev/null +++ b/samples/SingleRootAvaloniaApp/Root.cs @@ -0,0 +1,8 @@ +namespace AvaloniaApp; + +using Clock.ViewModels; +using Views; + +internal record Root( + Lazy MainWindow, + IClockViewModel ClockViewModel); \ No newline at end of file diff --git a/samples/SingleRootAvaloniaApp/Views/MainWindow.axaml b/samples/SingleRootAvaloniaApp/Views/MainWindow.axaml index a2dee47e0..7599bed97 100644 --- a/samples/SingleRootAvaloniaApp/Views/MainWindow.axaml +++ b/samples/SingleRootAvaloniaApp/Views/MainWindow.axaml @@ -7,12 +7,12 @@ x:Class="AvaloniaApp.Views.MainWindow" x:DataType="avaloniaApp:Composition" DataContext="{StaticResource Composition}" - Title="{Binding App.ClockViewModel.Time}" + Title="{Binding Root.ClockViewModel.Time}" Icon="/Assets/avalonia-logo.ico" FontFamily="Consolas" FontWeight="Bold"> - +