TGC.ConsoleBuilder
1.1.2
See the version list below for details.
dotnet add package TGC.ConsoleBuilder --version 1.1.2
NuGet\Install-Package TGC.ConsoleBuilder -Version 1.1.2
<PackageReference Include="TGC.ConsoleBuilder" Version="1.1.2" />
paket add TGC.ConsoleBuilder --version 1.1.2
#r "nuget: TGC.ConsoleBuilder, 1.1.2"
// Install TGC.ConsoleBuilder as a Cake Addin #addin nuget:?package=TGC.ConsoleBuilder&version=1.1.2 // Install TGC.ConsoleBuilder as a Cake Tool #tool nuget:?package=TGC.ConsoleBuilder&version=1.1.2
TGC.ConsoleBuilder
Using the ConsoleBuilder
There are two ways of using the ConsoleBuilder:
- You run it from a manually defined injected service
- You run it via Run()/RunAsync();
Running via injected service
var consoleAppBuilder = ConsoleBuilder.CreateApp(args);
var consoleApp = consoleAppBuilder.Build();
consoleApp.RunFromServiceProvider(s => s.GetRequiredService<ITestService>().DoStuff());
If you run it via an injected service, this service needs to be injected. This is done via implementing the interface IConsoleInjectionBuilder
. It is in this implementation you specify your dependencies. It could look like the following:
internal class ConsoleInjectionBuilder : IConsoleInjectionBuilder
{
public void Configure(IServiceCollection serviceCollection)
{
serviceCollection.AddScoped<ITestService, TestService>();
}
}
Running via Run()/RunAsync()
var consoleAppBuilder = ConsoleBuilder.CreateApp(args);
var consoleApp = consoleAppBuilder.Build();
await consoleApp.RunAsync();
// OR
await consoleApp.Run();
To be able to use Run or RunAsync you need to have implemented the interface IAsyncStartService or ISyncStartService. They are both executed via dependency injection so you are able to access your dependencies registered in IConsoleInjectionBuilder directly from your implementation.
Example of setup:
IConsoleInjectionBuilder
internal class ConsoleInjectionBuilder : IConsoleInjectionBuilder
{
public void Configure(IServiceCollection serviceCollection)
{
serviceCollection.AddScoped<ITestService, TestService>();
}
}
IAsyncStartService
internal class AsyncRunner : IAsyncStartService
{
private readonly ITestService _testService;
public AsyncRunner(ITestService testService)
{
_testService = testService;
}
public Task RunAsync()
{
_testService.ResolveImportantStuff();
_testService.StartBatchHandling();
//etc...
}
}
Roadmap
Implement Host Builder
At the moment, things has been manually wired. This is not ideal. Instead, it should wrap IHost.
Changelog
1.1.2
Added project url and updated README.md
0.1.0
Initial version - Not tested and ready for usage.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- TGC.CSharpCodingStandards (>= 1.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.