This repository is not maintained anymore. I have moved to a new repository, less confusing with golang :) Try JandaBox
.NET template provides console application startup code with dependency injection, logging, configuration and more...
To install this template use dotnet
command. It will automatically download template nuget package from https://www.nuget.org/packages/Janda.Go
dotnet new install Janda.Go
in earlier dotnet versions it was
dotnet new -i Janda.Go
Once the template is installed you can create new application from Console Go (C#) template.
dotnet new consolego
or
dotnet new consolego -n MyApp
The console main code is ready to "Run" with dependency injection and logging.
public void Run()
{
_logger.LogInformation("Hello, World");
_logger.LogWarning("No implementation");
throw new NotImplementedException("Fix it");
}
The Program.cs
code is going to look like this
// Created with Janda.Go http://github.com/Jandini/Janda.Go
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
namespace MyApp
{
class Program
{
static void Main()
{
try
{
using var provider = new ServiceCollection()
.AddTransient<IMain, Main>()
.AddLogging(builder => builder.AddConsole())
.BuildServiceProvider();
try
{
provider
.GetRequiredService<IMain>()
.Run();
}
catch (Exception ex)
{
provider.GetRequiredService<ILogger<Program>>()
.LogCritical(ex, ex.Message);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
If you like Serilog the same as I do use --useSerilog
or -us
option
dotnet new consolego -n MyApp -us
More information about Console Go template
dotnet new consolego -h
- .NET6
- Repository Layout
- The
src
andbin
folders - Default
README.md
file - Default
.gitignore
file - Default
launchSettings.json
file
- The
- GitHub Actions
Build
andTest
workflow file for .NET6
- Dependency Injection
- Main service with logging
- Service provider disposal
- Logging
Microsoft
orSerilog
log providers- Unhandled exceptions logging
- Version logging
- Dynamic logger
- Configuration
- Embedded
appsettings.json
file - Override embedded
appsettings.json
with the file - Settings binding
- Configuration and settings injection
- Embedded
- Command line parser
- Verbs and options parser
Go icon was downloaded from Flaticon.