From 7a92b930f7931d6abb78eaaf414f6c8a163f6558 Mon Sep 17 00:00:00 2001 From: Nikolay Pianikov Date: Sat, 13 Apr 2024 20:52:06 +0300 Subject: [PATCH] Revert "Improved templates" This reverts commit a8d5f924ad83990fd14b71972ba2799e1921261c. --- .../ConsoleAdapter.cs | 8 +++--- .../GlobalUsings.cs | 6 ----- .../Pure.DI.Template.ClassLibrary/IInput.cs | 2 +- .../Pure.DI.Template.ClassLibrary/IOutput.cs | 2 +- .../_CompositionName_.cs | 11 ++++++-- .../ConsoleAdapter.cs | 6 ++--- .../GlobalUsings.cs | 6 +---- .../Pure.DI.Template.ConsoleApp/IInput.cs | 2 +- .../Pure.DI.Template.ConsoleApp/IOutput.cs | 2 +- .../Pure.DI.Template.ConsoleApp/Program.cs | 27 +++++++++++-------- .../_CompositionName_.cs | 11 +++++--- 11 files changed, 44 insertions(+), 39 deletions(-) delete mode 100644 src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/GlobalUsings.cs diff --git a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/ConsoleAdapter.cs b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/ConsoleAdapter.cs index 1fb4e14f2..c1c7a1e16 100644 --- a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/ConsoleAdapter.cs +++ b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/ConsoleAdapter.cs @@ -1,10 +1,10 @@ +using System; + namespace _PureDIProjectName_; public class ConsoleAdapter: IInput, IOutput { - public ValueTask ReadLineAsync(CancellationToken cancellationToken = default) => - Console.In.ReadLineAsync(cancellationToken); + public string? ReadLine() => Console.ReadLine(); - public Task WriteLineAsync(string line = "", CancellationToken cancellationToken = default) => - Console.Out.WriteLineAsync(line.AsMemory(), cancellationToken); + public void WriteLine(string? line) => Console.WriteLine(line); } \ No newline at end of file diff --git a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/GlobalUsings.cs b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/GlobalUsings.cs deleted file mode 100644 index d4c31fb45..000000000 --- a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/GlobalUsings.cs +++ /dev/null @@ -1,6 +0,0 @@ -global using System; -global using System.Diagnostics; -global using System.Threading; -global using System.Threading.Tasks; -global using Pure.DI; -global using static Pure.DI.Lifetime; \ No newline at end of file diff --git a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/IInput.cs b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/IInput.cs index c2caac0d4..d237c87af 100644 --- a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/IInput.cs +++ b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/IInput.cs @@ -2,5 +2,5 @@ public interface IInput { - ValueTask ReadLineAsync(CancellationToken cancellationToken = default); + string? ReadLine(); } \ No newline at end of file diff --git a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/IOutput.cs b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/IOutput.cs index b83498d0b..9e7db15f3 100644 --- a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/IOutput.cs +++ b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/IOutput.cs @@ -2,5 +2,5 @@ namespace _PureDIProjectName_; public interface IOutput { - Task WriteLineAsync(string line = "", CancellationToken cancellationToken = default); + void WriteLine(string? line); } \ No newline at end of file diff --git a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/_CompositionName_.cs b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/_CompositionName_.cs index 253f05997..3a9a16516 100644 --- a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/_CompositionName_.cs +++ b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/_CompositionName_.cs @@ -1,9 +1,16 @@ -namespace _PureDIProjectName_; +using System.Diagnostics; +using Pure.DI; +using static Pure.DI.Lifetime; +namespace _PureDIProjectName_; + +/// +/// Pure.DI Composition Setup. Please see this example. +/// internal class $(CompositionName) { [Conditional("DI")] - private void Setup() => + void Setup() => DI.Setup(nameof($(CompositionName)), CompositionKind.Global) .Bind().As(Singleton).To(); } \ No newline at end of file diff --git a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/ConsoleAdapter.cs b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/ConsoleAdapter.cs index 4565e518a..5c39ff0a6 100644 --- a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/ConsoleAdapter.cs +++ b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/ConsoleAdapter.cs @@ -2,9 +2,7 @@ namespace _PureDIProjectName_; internal class ConsoleAdapter: IInput, IOutput { - public ValueTask ReadLineAsync(CancellationToken cancellationToken = default) => - Console.In.ReadLineAsync(cancellationToken); + public string? ReadLine() => Console.ReadLine(); - public Task WriteLineAsync(string line = "", CancellationToken cancellationToken = default) => - Console.Out.WriteLineAsync(line.AsMemory(), cancellationToken); + public void WriteLine(string? line) => Console.WriteLine(line); } \ No newline at end of file diff --git a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/GlobalUsings.cs b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/GlobalUsings.cs index f9a460828..7ac23b498 100644 --- a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/GlobalUsings.cs +++ b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/GlobalUsings.cs @@ -1,7 +1,3 @@ global using _PureDIProjectName_; global using System; -global using System.Diagnostics; -global using System.Threading; -global using System.Threading.Tasks; -global using Pure.DI; -global using static Pure.DI.Lifetime; \ No newline at end of file +global using System.Diagnostics; \ No newline at end of file diff --git a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/IInput.cs b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/IInput.cs index d59f528c3..591bc88ba 100644 --- a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/IInput.cs +++ b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/IInput.cs @@ -2,5 +2,5 @@ internal interface IInput { - ValueTask ReadLineAsync(CancellationToken cancellationToken = default); + string? ReadLine(); } \ No newline at end of file diff --git a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/IOutput.cs b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/IOutput.cs index fcaf4fc21..9c043c8dd 100644 --- a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/IOutput.cs +++ b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/IOutput.cs @@ -2,5 +2,5 @@ namespace _PureDIProjectName_; internal interface IOutput { - Task WriteLineAsync(string line = "", CancellationToken cancellationToken = default); + void WriteLine(string? line); } \ No newline at end of file diff --git a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/Program.cs b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/Program.cs index 77f6689f9..2c580063f 100644 --- a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/Program.cs +++ b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/Program.cs @@ -1,18 +1,23 @@ -var composition = new $(CompositionName)(args); -return await composition.Root.RunAsync(); +var composition = new $(CompositionName)(); +return composition.Root.Run(args); -internal partial class Program( - string[] args, - IInput input, - IOutput output) +internal partial class Program { - private async Task RunAsync(CancellationToken cancellationToken = default) + private readonly IInput _input; + private readonly IOutput _output; + + internal Program(IInput input, IOutput output) + { + _input = input ?? throw new ArgumentNullException(nameof(input)); + _output = output ?? throw new ArgumentNullException(nameof(output)); + } + + private int Run(string[] args) { - await output.WriteLineAsync("Hello!", cancellationToken); - await output.WriteLineAsync(string.Join(", ", args), cancellationToken); + _output.WriteLine("Hello!"); - await output.WriteLineAsync("Press the Enter key to exit.", cancellationToken); - await input.ReadLineAsync(cancellationToken); + _output.WriteLine("Press the Enter key to exit."); + _input.ReadLine(); return 0; } diff --git a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/_CompositionName_.cs b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/_CompositionName_.cs index ee671357c..3bcb4cd38 100644 --- a/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/_CompositionName_.cs +++ b/src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/_CompositionName_.cs @@ -1,11 +1,16 @@ -namespace _PureDIProjectName_; +using Pure.DI; +using static Pure.DI.Lifetime; +namespace _PureDIProjectName_; + +/// +/// Pure.DI Composition Setup. Please see this example. +/// internal partial class $(CompositionName) { [Conditional("DI")] - private void Setup() => + void Setup() => DI.Setup(nameof($(CompositionName))) - .Arg("args") .Bind().As(Singleton).To() .Root("Root"); } \ No newline at end of file