From 3d98d3e637e43dc6cbac372021f7d0938b666005 Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Sat, 24 Aug 2024 21:02:02 +0100 Subject: [PATCH 1/2] Update code example to align with snippet in CommandApp/DI documentation --- examples/Cli/Injection/Program.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/Cli/Injection/Program.cs b/examples/Cli/Injection/Program.cs index 813560d..3acc692 100644 --- a/examples/Cli/Injection/Program.cs +++ b/examples/Cli/Injection/Program.cs @@ -9,10 +9,11 @@ public class Program { public static int Main(string[] args) { - // Create a type registrar and register any dependencies. - // A type registrar is an adapter for a DI framework. var registrations = new ServiceCollection(); registrations.AddSingleton(); + + // Create a type registrar and register any dependencies. + // A type registrar is an adapter for a DI framework. var registrar = new TypeRegistrar(registrations); // Create a new command app with the registrar From d8ee9c44b5a52fce0ecebeaa58fb193d30486fbf Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Sat, 24 Aug 2024 21:12:52 +0100 Subject: [PATCH 2/2] Renamed TypeRegistrar to MyTypeRegistrar, making it more obvious it is a custom class the user must provide. --- .../Infrastructure/{TypeRegistrar.cs => MyTypeRegistrar.cs} | 6 +++--- .../Infrastructure/{TypeResolver.cs => MyTypeResolver.cs} | 4 ++-- examples/Cli/Injection/Program.cs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename examples/Cli/Injection/Infrastructure/{TypeRegistrar.cs => MyTypeRegistrar.cs} (81%) rename examples/Cli/Injection/Infrastructure/{TypeResolver.cs => MyTypeResolver.cs} (82%) diff --git a/examples/Cli/Injection/Infrastructure/TypeRegistrar.cs b/examples/Cli/Injection/Infrastructure/MyTypeRegistrar.cs similarity index 81% rename from examples/Cli/Injection/Infrastructure/TypeRegistrar.cs rename to examples/Cli/Injection/Infrastructure/MyTypeRegistrar.cs index 6651e67..ba9d1f5 100644 --- a/examples/Cli/Injection/Infrastructure/TypeRegistrar.cs +++ b/examples/Cli/Injection/Infrastructure/MyTypeRegistrar.cs @@ -4,18 +4,18 @@ namespace Injection.Infrastructure; -public sealed class TypeRegistrar : ITypeRegistrar +public sealed class MyTypeRegistrar : ITypeRegistrar { private readonly IServiceCollection _builder; - public TypeRegistrar(IServiceCollection builder) + public MyTypeRegistrar(IServiceCollection builder) { _builder = builder; } public ITypeResolver Build() { - return new TypeResolver(_builder.BuildServiceProvider()); + return new MyTypeResolver(_builder.BuildServiceProvider()); } public void Register(Type service, Type implementation) diff --git a/examples/Cli/Injection/Infrastructure/TypeResolver.cs b/examples/Cli/Injection/Infrastructure/MyTypeResolver.cs similarity index 82% rename from examples/Cli/Injection/Infrastructure/TypeResolver.cs rename to examples/Cli/Injection/Infrastructure/MyTypeResolver.cs index f3cf618..55af6fb 100644 --- a/examples/Cli/Injection/Infrastructure/TypeResolver.cs +++ b/examples/Cli/Injection/Infrastructure/MyTypeResolver.cs @@ -3,11 +3,11 @@ namespace Injection.Infrastructure; -public sealed class TypeResolver : ITypeResolver, IDisposable +public sealed class MyTypeResolver : ITypeResolver, IDisposable { private readonly IServiceProvider _provider; - public TypeResolver(IServiceProvider provider) + public MyTypeResolver(IServiceProvider provider) { _provider = provider ?? throw new ArgumentNullException(nameof(provider)); } diff --git a/examples/Cli/Injection/Program.cs b/examples/Cli/Injection/Program.cs index 3acc692..efd5d7e 100644 --- a/examples/Cli/Injection/Program.cs +++ b/examples/Cli/Injection/Program.cs @@ -14,7 +14,7 @@ public static int Main(string[] args) // Create a type registrar and register any dependencies. // A type registrar is an adapter for a DI framework. - var registrar = new TypeRegistrar(registrations); + var registrar = new MyTypeRegistrar(registrations); // Create a new command app with the registrar // and run it with the provided arguments.