From 1713ff3a0e61112392224695c0cacc5e635a0188 Mon Sep 17 00:00:00 2001 From: Nikolay Pianikov Date: Wed, 22 Jan 2025 10:16:31 +0300 Subject: [PATCH] Support for multiple hints --- readme/global-compositions.md | 4 ---- readme/service-collection.md | 2 +- samples/BlazorServerApp/Composition.cs | 1 + samples/BlazorWebAssemblyApp/Composition.cs | 1 + samples/GrpcService/Composition.cs | 1 + samples/MinimalWebAPI/Composition.cs | 1 + samples/WebAPI/Composition.cs | 1 + samples/WebApp/Composition.cs | 1 + .../any/Pure.DI/MS/ServiceProviderFactory.g.cs | 14 +++++++++++++- .../Advanced/GlobalCompositionsScenario.cs | 4 ---- .../BaseClassLibrary/ServiceCollectionScenario.cs | 7 +------ 11 files changed, 21 insertions(+), 16 deletions(-) diff --git a/readme/global-compositions.md b/readme/global-compositions.md index 98fdec81..0ca617f0 100644 --- a/readme/global-compositions.md +++ b/readme/global-compositions.md @@ -23,10 +23,6 @@ class MyGlobalComposition2 { static void Setup() => DI.Setup("Some name", kind: Global) - .Hint(Hint.OnCannotResolve, "Off") - .Hint(Hint.OnCannotResolvePartial, "On") - .Hint(Hint.OnNewRoot, "Off") - .Hint(Hint.OnNewRootPartial, "On") .Hint(Hint.ToString, "On"); } ``` diff --git a/readme/service-collection.md b/readme/service-collection.md index 8e7d91fa..95e496cb 100644 --- a/readme/service-collection.md +++ b/readme/service-collection.md @@ -38,8 +38,8 @@ partial class Composition : ServiceProviderFactory CreateServiceCollection(this); static void Setup() => - DI.Setup() + .DependsOn(Base) .Bind("Dependency Key").As(Lifetime.Singleton).To() .Bind().To() .Root(tag: "Dependency Key") diff --git a/samples/BlazorServerApp/Composition.cs b/samples/BlazorServerApp/Composition.cs index e7becd0e..eb0386f9 100644 --- a/samples/BlazorServerApp/Composition.cs +++ b/samples/BlazorServerApp/Composition.cs @@ -14,6 +14,7 @@ namespace BlazorServerApp; internal partial class Composition : ServiceProviderFactory { void Setup() => DI.Setup() + .DependsOn(Base) // View Models .Bind().To() // Provides the composition root for Clock view model diff --git a/samples/BlazorWebAssemblyApp/Composition.cs b/samples/BlazorWebAssemblyApp/Composition.cs index b76198f6..f4054b22 100644 --- a/samples/BlazorWebAssemblyApp/Composition.cs +++ b/samples/BlazorWebAssemblyApp/Composition.cs @@ -13,6 +13,7 @@ namespace BlazorWebAssemblyApp; internal partial class Composition : ServiceProviderFactory { void Setup() => DI.Setup() + .DependsOn(Base) // View Models .Bind().As(Singleton).To() // Provides the composition root for Clock view model diff --git a/samples/GrpcService/Composition.cs b/samples/GrpcService/Composition.cs index 3e0c595b..93c9f01c 100644 --- a/samples/GrpcService/Composition.cs +++ b/samples/GrpcService/Composition.cs @@ -10,6 +10,7 @@ namespace GrpcService; internal partial class Composition : ServiceProviderFactory { static void Setup() => DI.Setup() + .DependsOn(Base) // Provides the composition root for Greeter service .Root(); } \ No newline at end of file diff --git a/samples/MinimalWebAPI/Composition.cs b/samples/MinimalWebAPI/Composition.cs index c9f682d3..cbbb5284 100644 --- a/samples/MinimalWebAPI/Composition.cs +++ b/samples/MinimalWebAPI/Composition.cs @@ -11,6 +11,7 @@ namespace MinimalWebAPI; internal partial class Composition : ServiceProviderFactory { void Setup() => DI.Setup() + .DependsOn(Base) .Bind().As(Singleton).To() .Root() diff --git a/samples/WebAPI/Composition.cs b/samples/WebAPI/Composition.cs index e2b264b9..37feee2b 100644 --- a/samples/WebAPI/Composition.cs +++ b/samples/WebAPI/Composition.cs @@ -12,6 +12,7 @@ namespace WebAPI; internal partial class Composition : ServiceProviderFactory { static void Setup() => DI.Setup() + .DependsOn(Base) .Bind().As(Singleton).To() // Provides the composition root for Weather Forecast controller .Root(); diff --git a/samples/WebApp/Composition.cs b/samples/WebApp/Composition.cs index 7ed72c07..1e4e1591 100644 --- a/samples/WebApp/Composition.cs +++ b/samples/WebApp/Composition.cs @@ -12,6 +12,7 @@ namespace WebApp; internal partial class Composition : ServiceProviderFactory { static void Setup() => DI.Setup() + .DependsOn(Base) .Bind().As(Singleton).To() // Provides the composition root for Home controller .Root(); diff --git a/src/Pure.DI.MS/any/Pure.DI/MS/ServiceProviderFactory.g.cs b/src/Pure.DI.MS/any/Pure.DI/MS/ServiceProviderFactory.g.cs index 6ccccce1..50c34ae0 100644 --- a/src/Pure.DI.MS/any/Pure.DI/MS/ServiceProviderFactory.g.cs +++ b/src/Pure.DI.MS/any/Pure.DI/MS/ServiceProviderFactory.g.cs @@ -36,6 +36,18 @@ public class ServiceProviderFactory: IServiceProviderFactory + /// The name of the Pure.DI setup to use as a dependency in other setups. + /// + /// For example: + /// + /// void Setup() => + /// DI.Setup(nameof(Composition)).DependsOn(Base); + /// + /// + /// + protected const string Base = "Pure.DI.MS.ServiceProviderFactory"; + /// /// An instance of . /// @@ -51,7 +63,7 @@ public class ServiceProviderFactory: IServiceProviderFactory [global::System.Diagnostics.Conditional("A2768DE22DE3E430C9653990D516CC9B")] private static void HintsSetup() => - global::Pure.DI.DI.Setup("", global::Pure.DI.CompositionKind.Global) + global::Pure.DI.DI.Setup(Base, global::Pure.DI.CompositionKind.Internal) .Hint(global::Pure.DI.Hint.OnCannotResolve, "On") .Hint(global::Pure.DI.Hint.OnCannotResolvePartial, "Off") .Hint(global::Pure.DI.Hint.OnNewRoot, "On") diff --git a/tests/Pure.DI.UsageTests/Advanced/GlobalCompositionsScenario.cs b/tests/Pure.DI.UsageTests/Advanced/GlobalCompositionsScenario.cs index 9d2f220c..3df410ec 100644 --- a/tests/Pure.DI.UsageTests/Advanced/GlobalCompositionsScenario.cs +++ b/tests/Pure.DI.UsageTests/Advanced/GlobalCompositionsScenario.cs @@ -35,10 +35,6 @@ class MyGlobalComposition2 { static void Setup() => DI.Setup("Some name", kind: Global) - .Hint(Hint.OnCannotResolve, "Off") - .Hint(Hint.OnCannotResolvePartial, "On") - .Hint(Hint.OnNewRoot, "Off") - .Hint(Hint.OnNewRootPartial, "On") .Hint(Hint.ToString, "On"); } // } \ No newline at end of file diff --git a/tests/Pure.DI.UsageTests/BaseClassLibrary/ServiceCollectionScenario.cs b/tests/Pure.DI.UsageTests/BaseClassLibrary/ServiceCollectionScenario.cs index dc8a59a7..b66ea261 100644 --- a/tests/Pure.DI.UsageTests/BaseClassLibrary/ServiceCollectionScenario.cs +++ b/tests/Pure.DI.UsageTests/BaseClassLibrary/ServiceCollectionScenario.cs @@ -64,13 +64,8 @@ partial class Composition : ServiceProviderFactory CreateServiceCollection(this); static void Setup() => -// } - // OnCannotResolve = On - // OnCannotResolvePartial = Off - // OnNewRoot = On - // OnNewRootPartial = Off -// { DI.Setup() + .DependsOn(Base) .Bind("Dependency Key").As(Lifetime.Singleton).To() .Bind().To() .Root(tag: "Dependency Key")