Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Aug 11, 2024
1 parent 9b02ad1 commit 1f50601
Show file tree
Hide file tree
Showing 29 changed files with 57 additions and 51 deletions.
7 changes: 6 additions & 1 deletion readme/Avalonia.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ A single instance of the _Composition_ class is defined as a static resource in
</Application>
```

<details>
<summary>Changes to App.axaml.cs are only needed if you want to add logic to dispose of resources.</summary>

The associated application [App.axaml.cs](/samples/AvaloniaApp/App.axaml.cs) class is looking like:

```c#
Expand All @@ -73,6 +76,8 @@ public class App : Application
}
```

</details>

All previously defined composition roots are now accessible from [markup](/samples/AvaloniaApp/Views/MainWindow.xaml) without any effort, such as _ClockViewModel_:

```xaml
Expand Down Expand Up @@ -110,7 +115,7 @@ The [project file](/samples/AvaloniaApp/AvaloniaApp.csproj) looks like this:
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.29">
<PackageReference Include="Pure.DI" Version="2.1.30">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
5 changes: 5 additions & 0 deletions readme/AvaloniaPageTemplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ A single instance of the _Composition_ class is defined as a static resource in
</Application>
```

<details>
<summary>Changes to App.axaml.cs are only needed if you want to add logic to dispose of resources.</summary>

The associated application [App.axaml.cs](/samples/AvaloniaApp/App.axaml.cs) class is looking like:

```c#
Expand All @@ -73,6 +76,8 @@ public class App : Application
}
```

</details>

All previously defined composition roots are now accessible from [markup](/samples/AvaloniaApp/Views/MainWindow.xaml) without any effort, such as _ClockViewModel_:

```xaml
Expand Down
2 changes: 1 addition & 1 deletion readme/BlazorServerApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The [project file](/samples/BlazorServerApp/BlazorServerApp.csproj) looks like t
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.29">
<PackageReference Include="Pure.DI" Version="2.1.30">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/BlazorWebAssemblyApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The [project file](/samples/BlazorWebAssemblyApp/BlazorWebAssemblyApp.csproj) lo
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.29">
<PackageReference Include="Pure.DI" Version="2.1.30">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/Console.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ The [project file](/samples/ShroedingersCat/ShroedingersCat.csproj) looks like t
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.29">
<PackageReference Include="Pure.DI" Version="2.1.30">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/ConsoleNativeAOT.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The [project file](/samples/ShroedingersCatNativeAOT/ShroedingersCatNativeAOT.cs
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.29">
<PackageReference Include="Pure.DI" Version="2.1.30">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/ConsoleTopLevelStatements.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The [project file](/samples/ShroedingersCatTopLevelStatements/ShroedingersCatTop
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.29">
<PackageReference Include="Pure.DI" Version="2.1.30">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/GrpcService.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The [project file](/samples/GrpcService/GrpcService.csproj) looks like this:
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.29">
<PackageReference Include="Pure.DI" Version="2.1.30">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/Maui.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ The [project file](/samples/MAUIApp/MAUIApp.csproj) looks like this:
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)"/>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0"/>
<PackageReference Include="Pure.DI" Version="2.1.29">
<PackageReference Include="Pure.DI" Version="2.1.30">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/MinimalWebAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ The [project file](/samples/WebAPI/WebAPI.csproj) looks like this:
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.29">
<PackageReference Include="Pure.DI" Version="2.1.30">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/WebAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The [project file](/samples/WebAPI/WebAPI.csproj) looks like this:
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.29">
<PackageReference Include="Pure.DI" Version="2.1.30">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/WebApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The [project file](/samples/WebApp/WebApp.csproj) looks like this:
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.29">
<PackageReference Include="Pure.DI" Version="2.1.30">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/WinFormsApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The [project file](/samples/WinFormsApp/WinFormsApp.csproj) looks like this:
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.29">
<PackageReference Include="Pure.DI" Version="2.1.30">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/WinFormsAppNetCore.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The [project file](/samples/WinFormsAppNetCore/WinFormsAppNetCore.csproj) looks
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.29">
<PackageReference Include="Pure.DI" Version="2.1.30">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/Wpf.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The [project file](/samples/WpfAppNetCore/WpfAppNetCore.csproj) looks like this:
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.1.29">
<PackageReference Include="Pure.DI" Version="2.1.30">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions readme/bind-attribute-for-a-generic-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ partial class Composition

IDependency<int> transientIDependency1;
{
Facade localValue24 = _root._singletonFacade39!;
transientIDependency1 = localValue24.GetDependency<int>();
Facade localInstance_1182D12724 = _root._singletonFacade39!;
transientIDependency1 = localInstance_1182D12724.GetDependency<int>();
}

return new Service(transientIDependency1);
Expand Down
4 changes: 2 additions & 2 deletions readme/bind-attribute-with-lifetime-and-tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions readme/bind-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions readme/exposed-generic-roots-with-args.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ partial class Composition
Integration.IMyGenericService<int> transientIMyGenericService1;
{
int localId1 = id;
Integration.CompositionWithGenericRootsAndArgsInOtherProject localValue2 = _root._singletonCompositionWithGenericRootsAndArgsInOtherProject40!;
transientIMyGenericService1 = localValue2.GetMyService<int>(localId1);
Integration.CompositionWithGenericRootsAndArgsInOtherProject localInstance_1182D1272 = _root._singletonCompositionWithGenericRootsAndArgsInOtherProject40!;
transientIMyGenericService1 = localInstance_1182D1272.GetMyService<int>(localId1);
}

return new Program(transientIMyGenericService1);
Expand Down
4 changes: 2 additions & 2 deletions readme/exposed-generic-roots.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ partial class Composition

Integration.IMyGenericService<int> transientIMyGenericService1;
{
Integration.CompositionWithGenericRootsInOtherProject localValue0 = _root._singletonCompositionWithGenericRootsInOtherProject39!;
transientIMyGenericService1 = localValue0.GetMyService<int>();
Integration.CompositionWithGenericRootsInOtherProject localInstance_1182D1270 = _root._singletonCompositionWithGenericRootsInOtherProject39!;
transientIMyGenericService1 = localInstance_1182D1270.GetMyService<int>();
}

return new Program(transientIMyGenericService1);
Expand Down
4 changes: 2 additions & 2 deletions readme/exposed-roots-via-arg.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions readme/exposed-roots-via-root-arg.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions readme/exposed-roots-with-tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions readme/exposed-roots.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion samples/SingleRootAvaloniaApp/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
13 changes: 0 additions & 13 deletions samples/SingleRootAvaloniaApp/AppDataContext.cs

This file was deleted.

7 changes: 4 additions & 3 deletions samples/SingleRootAvaloniaApp/Composition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppDataContext>(nameof(App))
// Single composition root for the application
.Root<Root>(nameof(Root))

.Bind().As(Singleton).To<AppDataContext>()
.Bind().As(Singleton).To<Root>()

// View Models
.Bind().To<ClockViewModel>()
Expand Down
8 changes: 8 additions & 0 deletions samples/SingleRootAvaloniaApp/Root.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace AvaloniaApp;

using Clock.ViewModels;
using Views;

internal record Root(
Lazy<MainWindow> MainWindow,
IClockViewModel ClockViewModel);
4 changes: 2 additions & 2 deletions samples/SingleRootAvaloniaApp/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" DataContext="{Binding App.ClockViewModel}">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" DataContext="{Binding Root.ClockViewModel}">
<TextBlock Text="{Binding Date}" FontSize="64" HorizontalAlignment="Center" />
<TextBlock Text="{Binding Time}" FontSize="128" HorizontalAlignment="Center" />
</StackPanel>
Expand Down

0 comments on commit 1f50601

Please sign in to comment.