Skip to content

This is a project template for .Net Core 3.1 console app, pre configured Autofac, Serilog, AutoMapper, Newtonsoft.Json

License

Notifications You must be signed in to change notification settings

superwalnut/dotnet-console-app-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Template - .Net Core 3.1 Console app + Autofac + Serilog + AutoMapper

This is a project template for .Net Core 3.1 Console app, pre-configured Autofac, Serilog, AutoMapper, Newtonsoft.Json using dotnet new -i Superwalnut.NetCoreConsoleTemplate to install project as a template, And using dotnet new core-console-autofac to create a project with the template.

Pre-request

Table of Contents


Features

This is a development project template, it is NOT production ready. It only kickstarting your project so that you don't need to build from scratch.

  1. pre-Configured Autofac 5.2.0 registrations setup.
  2. pre-Configured Serilog 2.9.0 console sinks.
  3. pre-Configured AutoMapper 10.0.0.
  4. pre-Installed Newtonsoft.Json 12.0.3

Installation

$ dotnet new -i Superwalnut.NetCoreConsoleTemplate

You should see '.Net Core Console Autofac+Serilog' in your template list by dotnet new -l

  • Using dotnet new core-console-autofac -n <your-project-name> to create a project with your own project name using this template
$ dotnet new core-console-autofac -n NetCoreDemo -o NetCoreDemo

This creates a project in folder NetCoreDemo


Documentation

Pre-configured Autofac

ContainerBuilder() that you can populate IServiceCollection and register your autofac modules in Startup.cs. Taking ConsoleModule from the template as an example, you can also create modules for your Service Layer, Repository Layer, etc.

        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            ...
            builder.RegisterModule<ConsoleModule>();

            var container = builder.Build();
            return container.Resolve<IServiceProvider>();
        }

Serilog & Automapper are registered in the ConsoleModule,

    public class ConsoleModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            builder.AddAutoMapper(x=>x.AddProfile<MyAutoMapperProfile>());
        }
    }

Pre-configured Serilog

With console sinks in the appsettings.json

  "Serilog": {
    "Using": [ "Serilog.Sinks.Console" ],
    "MinimumLevel": "Information",
    "WriteTo": [
      {
        "Name": "Console"        
      }
    ]
  }

And Serilog configuration in the startup.cs

        public static void CreateLogger(IConfigurationRoot configuration)
        {
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                .Enrich.FromLogContext()
                .ReadFrom.Configuration(configuration)
                .CreateLogger();
        }

Pre-configured AutoMapper

With created example profile,

    public class MyAutoMapperProfile : Profile
    {
        public MyAutoMapperProfile()
        {
            CreateMap<Foo, FooDto>();
            ...
        }
    }

And register the profile in ConsoleModule for AutoMapper,

    public class ConsoleModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            ...
            builder.AddAutoMapper(x=>x.AddProfile<MyAutoMapperProfile>());
        }
    }

Support

Reach out to me at one of the following places!


License

License


About

This is a project template for .Net Core 3.1 console app, pre configured Autofac, Serilog, AutoMapper, Newtonsoft.Json

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages