-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CompositionRoot which will be responsible for creating all commands and required types. Currently, the implementation is incomplete and composition is still split between CompositionRoot and GenerateCommand (which uses the Autofac DI container)
- Loading branch information
Showing
3 changed files
with
113 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using Grynwald.ChangeLog.CommandLine; | ||
using Grynwald.ChangeLog.Commands; | ||
using Grynwald.ChangeLog.Configuration; | ||
using Grynwald.Utilities.Logging; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Grynwald.ChangeLog | ||
{ | ||
internal class CompositionRoot : IDisposable | ||
{ | ||
|
||
public GenerateCommand CreateGenerateCommand(GenerateCommandLineParameters commandLine) | ||
{ | ||
if (commandLine is null) | ||
throw new ArgumentNullException(nameof(commandLine)); | ||
|
||
return new GenerateCommand( | ||
commandLine: commandLine, | ||
logger: CreateLogger<GenerateCommand>(commandLine.Verbose), | ||
commandLineValidator: new GenerateCommandLineParametersValidator(), | ||
configurationValidator: new ConfigurationValidator() | ||
); | ||
} | ||
|
||
|
||
|
||
public ILogger<T> CreateLogger<T>(bool verbose) | ||
{ | ||
var loggerFactory = new LoggerFactory(); | ||
var provider = new SimpleConsoleLoggerProvider(CreateLoggerConfiguration(verbose)); | ||
loggerFactory.AddProvider(provider); | ||
|
||
return new Logger<T>(loggerFactory); | ||
} | ||
|
||
|
||
//TODO: Temporary workaround | ||
public static SimpleConsoleLoggerConfiguration CreateLoggerConfiguration(bool verbose) | ||
{ | ||
return verbose | ||
? new SimpleConsoleLoggerConfiguration(LogLevel.Debug, true, true) | ||
: new SimpleConsoleLoggerConfiguration(LogLevel.Information, false, true); | ||
} | ||
|
||
|
||
public void Dispose() | ||
{ | ||
//TODO | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters