Skip to content

Commit

Permalink
Revert "Improved templates"
Browse files Browse the repository at this point in the history
This reverts commit a8d5f92.
  • Loading branch information
NikolayPianikov committed Apr 13, 2024
1 parent 1415d83 commit 7a92b93
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;

namespace _PureDIProjectName_;

public class ConsoleAdapter: IInput, IOutput
{
public ValueTask<string?> 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);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public interface IInput
{
ValueTask<string?> ReadLineAsync(CancellationToken cancellationToken = default);
string? ReadLine();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ namespace _PureDIProjectName_;

public interface IOutput
{
Task WriteLineAsync(string line = "", CancellationToken cancellationToken = default);
void WriteLine(string? line);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
namespace _PureDIProjectName_;
using System.Diagnostics;
using Pure.DI;
using static Pure.DI.Lifetime;

namespace _PureDIProjectName_;

/// <summary>
/// Pure.DI Composition Setup. Please see <see href="https://github.com/DevTeam/Pure.DI.Solution">this</see> example.
/// </summary>
internal class $(CompositionName)
{
[Conditional("DI")]
private void Setup() =>
void Setup() =>
DI.Setup(nameof($(CompositionName)), CompositionKind.Global)
.Bind().As(Singleton).To<ConsoleAdapter>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ namespace _PureDIProjectName_;

internal class ConsoleAdapter: IInput, IOutput
{
public ValueTask<string?> 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);
}
Original file line number Diff line number Diff line change
@@ -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;
global using System.Diagnostics;
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

internal interface IInput
{
ValueTask<string?> ReadLineAsync(CancellationToken cancellationToken = default);
string? ReadLine();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ namespace _PureDIProjectName_;

internal interface IOutput
{
Task WriteLineAsync(string line = "", CancellationToken cancellationToken = default);
void WriteLine(string? line);
}
Original file line number Diff line number Diff line change
@@ -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<int> 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
namespace _PureDIProjectName_;
using Pure.DI;
using static Pure.DI.Lifetime;

namespace _PureDIProjectName_;

/// <summary>
/// Pure.DI Composition Setup. Please see <see href="https://github.com/DevTeam/Pure.DI.Solution">this</see> example.
/// </summary>
internal partial class $(CompositionName)
{
[Conditional("DI")]
private void Setup() =>
void Setup() =>
DI.Setup(nameof($(CompositionName)))
.Arg<string[]>("args")
.Bind().As(Singleton).To<ConsoleAdapter>()
.Root<Program>("Root");
}

0 comments on commit 7a92b93

Please sign in to comment.