Skip to content
This repository has been archived by the owner on Mar 18, 2023. It is now read-only.

Jandini/Janda.Go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This repository is not maintained anymore. I have moved to a new repository, less confusing with golang :) Try JandaBox

Janda.Go

.NET NuGet

.NET template provides console application startup code with dependency injection, logging, configuration and more...

JandaGo

Install

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

Start

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");
}

image

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);
            }
        }
    }
}

Serilog

If you like Serilog the same as I do use --useSerilog or -us option

dotnet new consolego -n MyApp -us

image

Help

More information about Console Go template

dotnet new consolego -h  

Features

  • .NET6
  • Repository Layout
    • The src and bin folders
    • Default README.md file
    • Default .gitignore file
    • Default launchSettings.json file
  • GitHub Actions
    • Build and Test workflow file for .NET6
  • Dependency Injection
    • Main service with logging
    • Service provider disposal
  • Logging
    • Microsoft or Serilog 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
  • Command line parser
    • Verbs and options parser

Resources

Go icon was downloaded from Flaticon.

About

Console application startup code including dependency injection, logging, configuration and more...

Resources

Stars

Watchers

Forks