From 4a48dee7192381fa1c84d6d4dfa95ff31e8c0c36 Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Sat, 24 Aug 2024 16:54:28 +0100 Subject: [PATCH 1/4] Fixed broken links to the examples project from preparation for 1.0 See: https://github.com/spectreconsole/spectre.console/issues/1602#issuecomment-2276622800 --- docs/input/cli/command-help.md | 2 +- docs/input/cli/commandApp.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/input/cli/command-help.md b/docs/input/cli/command-help.md index f83eca6c0..0e4a6e922 100644 --- a/docs/input/cli/command-help.md +++ b/docs/input/cli/command-help.md @@ -71,5 +71,5 @@ public static class Program } ``` -There is a working [example of a custom help provider](https://github.com/spectreconsole/spectre.console/tree/main/examples/Cli/Help) demonstrating this. +There is a working [example of a custom help provider](https://github.com/spectreconsole/examples/tree/main/examples/Cli/Help) demonstrating this. diff --git a/docs/input/cli/commandApp.md b/docs/input/cli/commandApp.md index 182cb37da..44a3993f3 100644 --- a/docs/input/cli/commandApp.md +++ b/docs/input/cli/commandApp.md @@ -75,7 +75,7 @@ var app = new CommandApp(registrar); return app.Run(args); ``` -`TypeRegistrar` is a custom class that must be created by the user. This [example using `Microsoft.Extensions.DependencyInjection` as the container](https://github.com/spectreconsole/spectre.console/tree/main/examples/Cli/Injection) provides an example `TypeRegistrar` and `TypeResolver` that can be added to your application with small adjustments for your DI container. +`TypeRegistrar` is a custom class that must be created by the user. This [example using `Microsoft.Extensions.DependencyInjection` as the container](https://github.com/spectreconsole/examples/tree/main/examples/Cli/Injection) provides an example `TypeRegistrar` and `TypeResolver` that can be added to your application with small adjustments for your DI container. Hint: If you do write your own implementation of `TypeRegistrar` and `TypeResolver` and you have some form of unit tests in place for your project, there is a utility `TypeRegistrarBaseTests` available that can be used to ensure your implementations adhere to the required implementation. Simply call `TypeRegistrarBaseTests.RunAllTests()` and expect no `TypeRegistrarBaseTests.TestFailedException` to be thrown. @@ -89,4 +89,4 @@ This provides an opportunity to modify the result and also to tear down any infr The `Intercept`-Method of each interceptor is run before the command is executed and the `InterceptResult`-Method is run after it. These are typically used for configuring logging or other infrastructure concerns. -For an example of using the interceptor to configure logging, see the [Serilog demo](https://github.com/spectreconsole/spectre.console/tree/main/examples/Cli/Logging). +For an example of using the interceptor to configure logging, see the [Serilog demo](https://github.com/spectreconsole/examples/tree/main/examples/Cli/Logging). From a1dd5e771b72be8c13702bfc022c68f22df661dc Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Sat, 24 Aug 2024 21:07:00 +0100 Subject: [PATCH 2/4] Rewrote the Dependency Injection section for better clarity and readability. --- docs/input/cli/commandApp.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/input/cli/commandApp.md b/docs/input/cli/commandApp.md index 44a3993f3..ec8a8ba36 100644 --- a/docs/input/cli/commandApp.md +++ b/docs/input/cli/commandApp.md @@ -75,10 +75,13 @@ var app = new CommandApp(registrar); return app.Run(args); ``` -`TypeRegistrar` is a custom class that must be created by the user. This [example using `Microsoft.Extensions.DependencyInjection` as the container](https://github.com/spectreconsole/examples/tree/main/examples/Cli/Injection) provides an example `TypeRegistrar` and `TypeResolver` that can be added to your application with small adjustments for your DI container. + + `TypeRegistrar` is a custom class that implements [ITypeRegistrar](xref:T:Spectre.Console.Cli.ITypeRegistrar) and must be provided by the user. + -Hint: If you do write your own implementation of `TypeRegistrar` and `TypeResolver` and you have some form of unit tests in place for your project, -there is a utility `TypeRegistrarBaseTests` available that can be used to ensure your implementations adhere to the required implementation. Simply call `TypeRegistrarBaseTests.RunAllTests()` and expect no `TypeRegistrarBaseTests.TestFailedException` to be thrown. +There is a working [example of dependency injection](https://github.com/spectreconsole/examples/tree/main/examples/Cli/Injection) that uses `Microsoft.Extensions.DependencyInjection` as the container. Example implementations of `TypeRegistrar` and `TypeResolver` are provided, which you can copy and paste to your application for dependency injection. + +Unit testing your `TypeRegistrar` and `TypeResolver` implementations is done using the utility `TypeRegistrarBaseTests` included in `Spectre.Console.Testing`. Simply call `TypeRegistrarBaseTests.RunAllTests()` and expect no `TypeRegistrarBaseTests.TestFailedException` to be thrown. ## Interception Interceptors can be registered with the `TypeRegistrar` (or with a custom DI-Container). Alternatively, `CommandApp` also provides a `SetInterceptor` configuration. From 2f2f387b1f95bbc8d45b72fbc9f21537967ea618 Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Sat, 24 Aug 2024 21:11:06 +0100 Subject: [PATCH 3/4] Syntax fix: Should reference interfaces, not implementation --- docs/input/cli/commandApp.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/input/cli/commandApp.md b/docs/input/cli/commandApp.md index ec8a8ba36..54da8fd2a 100644 --- a/docs/input/cli/commandApp.md +++ b/docs/input/cli/commandApp.md @@ -79,9 +79,9 @@ return app.Run(args); `TypeRegistrar` is a custom class that implements [ITypeRegistrar](xref:T:Spectre.Console.Cli.ITypeRegistrar) and must be provided by the user. -There is a working [example of dependency injection](https://github.com/spectreconsole/examples/tree/main/examples/Cli/Injection) that uses `Microsoft.Extensions.DependencyInjection` as the container. Example implementations of `TypeRegistrar` and `TypeResolver` are provided, which you can copy and paste to your application for dependency injection. +There is a working [example of dependency injection](https://github.com/spectreconsole/examples/tree/main/examples/Cli/Injection) that uses `Microsoft.Extensions.DependencyInjection` as the container. Example implementations of `ITypeRegistrar` and `ITypeResolver` are provided, which you can copy and paste to your application for dependency injection. -Unit testing your `TypeRegistrar` and `TypeResolver` implementations is done using the utility `TypeRegistrarBaseTests` included in `Spectre.Console.Testing`. Simply call `TypeRegistrarBaseTests.RunAllTests()` and expect no `TypeRegistrarBaseTests.TestFailedException` to be thrown. +Unit testing your `ITypeRegistrar` and `ITypeResolver` implementations is done using the utility `TypeRegistrarBaseTests` included in `Spectre.Console.Testing`. Simply call `TypeRegistrarBaseTests.RunAllTests()` and expect no `TypeRegistrarBaseTests.TestFailedException` to be thrown. ## Interception Interceptors can be registered with the `TypeRegistrar` (or with a custom DI-Container). Alternatively, `CommandApp` also provides a `SetInterceptor` configuration. From 8ec71c073730f5429772bc5f62406f5b719ea997 Mon Sep 17 00:00:00 2001 From: Frank Ray <52075808+FrankRay78@users.noreply.github.com> Date: Sat, 24 Aug 2024 21:12:31 +0100 Subject: [PATCH 4/4] Renamed TypeRegistrar to MyTypeRegistrar, making it more obvious it is a custom class the user must provide. --- docs/input/cli/commandApp.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/input/cli/commandApp.md b/docs/input/cli/commandApp.md index 54da8fd2a..33444d070 100644 --- a/docs/input/cli/commandApp.md +++ b/docs/input/cli/commandApp.md @@ -67,7 +67,7 @@ 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); +var registrar = new MyTypeRegistrar(registrations); // Create a new command app with the registrar // and run it with the provided arguments. @@ -76,7 +76,7 @@ return app.Run(args); ``` - `TypeRegistrar` is a custom class that implements [ITypeRegistrar](xref:T:Spectre.Console.Cli.ITypeRegistrar) and must be provided by the user. + `MyTypeRegistrar` is a custom class that implements [ITypeRegistrar](xref:T:Spectre.Console.Cli.ITypeRegistrar) and must be provided by the user. There is a working [example of dependency injection](https://github.com/spectreconsole/examples/tree/main/examples/Cli/Injection) that uses `Microsoft.Extensions.DependencyInjection` as the container. Example implementations of `ITypeRegistrar` and `ITypeResolver` are provided, which you can copy and paste to your application for dependency injection.