From 81506c0523f443b5b93494e2b78289619ab485e4 Mon Sep 17 00:00:00 2001 From: Nikolay Pianikov Date: Thu, 12 Dec 2024 17:18:04 +0300 Subject: [PATCH] Update README.md --- readme/func-with-arguments.md | 24 +++++++++---------- readme/func-with-tag.md | 11 ++++----- readme/func.md | 2 +- .../BaseClassLibrary/FuncScenario.cs | 2 +- .../FuncWithArgumentsScenario.cs | 24 +++++++++---------- .../BaseClassLibrary/FuncWithTagScenario.cs | 11 ++++----- 6 files changed, 34 insertions(+), 40 deletions(-) diff --git a/readme/func-with-arguments.md b/readme/func-with-arguments.md index bfe9586b..4fa7d203 100644 --- a/readme/func-with-arguments.md +++ b/readme/func-with-arguments.md @@ -37,17 +37,14 @@ interface IService ImmutableArray Dependencies { get; } } -class Service : IService +class Service(Func dependencyFactory): IService { - public Service(Func dependencyFactory) => - Dependencies = - [ - ..Enumerable - .Range(0, 10) - .Select((_, index) => dependencyFactory(index, 99)) - ]; - - public ImmutableArray Dependencies { get; } + public ImmutableArray Dependencies { get; } = + [ + dependencyFactory(0, 99), + dependencyFactory(1, 99), + dependencyFactory(2, 99) + ]; } DI.Setup(nameof(Composition)) @@ -75,9 +72,10 @@ DI.Setup(nameof(Composition)) var composition = new Composition(); var service = composition.Root; -service.Dependencies.Length.ShouldBe(10); -service.Dependencies[3].Id.ShouldBe(3); -service.Dependencies[3].SubId.ShouldBe(99); +service.Dependencies.Length.ShouldBe(3); +service.Dependencies[0].Id.ShouldBe(0); +service.Dependencies[1].Id.ShouldBe(1); +service.Dependencies[2].Id.ShouldBe(2); ``` Using a binding of the form `.Bind().To("some statement")` is a kind of hack that allows you to replace an injection with just its own string. diff --git a/readme/func-with-tag.md b/readme/func-with-tag.md index 82780ad3..c66a6eb3 100644 --- a/readme/func-with-tag.md +++ b/readme/func-with-tag.md @@ -13,14 +13,13 @@ interface IService ImmutableArray Dependencies { get; } } -class Service([Tag("my tag")] Func dependencyFactory) - : IService +class Service([Tag("my tag")] Func dependencyFactory): IService { public ImmutableArray Dependencies { get; } = [ - ..Enumerable - .Range(0, 10) - .Select(_ => dependencyFactory()) + dependencyFactory(), + dependencyFactory(), + dependencyFactory() ]; } @@ -33,7 +32,7 @@ DI.Setup(nameof(Composition)) var composition = new Composition(); var service = composition.Root; -service.Dependencies.Length.ShouldBe(10); +service.Dependencies.Length.ShouldBe(3); ``` The following partial class will be generated: diff --git a/readme/func.md b/readme/func.md index 4dc7d9b5..3d586760 100644 --- a/readme/func.md +++ b/readme/func.md @@ -15,7 +15,7 @@ interface IService ImmutableArray Dependencies { get; } } -class Service(Func dependencyFactory) : IService +class Service(Func dependencyFactory): IService { public ImmutableArray Dependencies => [ diff --git a/tests/Pure.DI.UsageTests/BaseClassLibrary/FuncScenario.cs b/tests/Pure.DI.UsageTests/BaseClassLibrary/FuncScenario.cs index 551d08d4..347b8f12 100644 --- a/tests/Pure.DI.UsageTests/BaseClassLibrary/FuncScenario.cs +++ b/tests/Pure.DI.UsageTests/BaseClassLibrary/FuncScenario.cs @@ -26,7 +26,7 @@ interface IService ImmutableArray Dependencies { get; } } -class Service(Func dependencyFactory) : IService +class Service(Func dependencyFactory): IService { public ImmutableArray Dependencies => [ diff --git a/tests/Pure.DI.UsageTests/BaseClassLibrary/FuncWithArgumentsScenario.cs b/tests/Pure.DI.UsageTests/BaseClassLibrary/FuncWithArgumentsScenario.cs index cd50f649..a1c62b17 100644 --- a/tests/Pure.DI.UsageTests/BaseClassLibrary/FuncWithArgumentsScenario.cs +++ b/tests/Pure.DI.UsageTests/BaseClassLibrary/FuncWithArgumentsScenario.cs @@ -54,17 +54,14 @@ interface IService ImmutableArray Dependencies { get; } } -class Service : IService +class Service(Func dependencyFactory): IService { - public Service(Func dependencyFactory) => - Dependencies = - [ - ..Enumerable - .Range(0, 10) - .Select((_, index) => dependencyFactory(index, 99)) - ]; - - public ImmutableArray Dependencies { get; } + public ImmutableArray Dependencies { get; } = + [ + dependencyFactory(0, 99), + dependencyFactory(1, 99), + dependencyFactory(2, 99) + ]; } // } @@ -100,9 +97,10 @@ public void Run() var composition = new Composition(); var service = composition.Root; - service.Dependencies.Length.ShouldBe(10); - service.Dependencies[3].Id.ShouldBe(3); - service.Dependencies[3].SubId.ShouldBe(99); + service.Dependencies.Length.ShouldBe(3); + service.Dependencies[0].Id.ShouldBe(0); + service.Dependencies[1].Id.ShouldBe(1); + service.Dependencies[2].Id.ShouldBe(2); // } composition.SaveClassDiagram(); } diff --git a/tests/Pure.DI.UsageTests/BaseClassLibrary/FuncWithTagScenario.cs b/tests/Pure.DI.UsageTests/BaseClassLibrary/FuncWithTagScenario.cs index b50c3cc9..82753f75 100644 --- a/tests/Pure.DI.UsageTests/BaseClassLibrary/FuncWithTagScenario.cs +++ b/tests/Pure.DI.UsageTests/BaseClassLibrary/FuncWithTagScenario.cs @@ -24,14 +24,13 @@ interface IService ImmutableArray Dependencies { get; } } -class Service([Tag("my tag")] Func dependencyFactory) - : IService +class Service([Tag("my tag")] Func dependencyFactory): IService { public ImmutableArray Dependencies { get; } = [ - ..Enumerable - .Range(0, 10) - .Select(_ => dependencyFactory()) + dependencyFactory(), + dependencyFactory(), + dependencyFactory() ]; } // } @@ -51,7 +50,7 @@ public void Run() var composition = new Composition(); var service = composition.Root; - service.Dependencies.Length.ShouldBe(10); + service.Dependencies.Length.ShouldBe(3); // } composition.SaveClassDiagram(); }