All Projects → simplesoft-pt → Hosting

simplesoft-pt / Hosting

Licence: MIT license
Library to simplify the hosting of console applications by making it easier to setup dependency injection, logging and configurations

Programming Languages

C#
18002 projects
powershell
5483 projects

Projects that are alternatives of or similar to Hosting

Meadow
Integrated Ethereum implementation and tool suite focused on Solidity testing and development.
Stars: ✭ 126 (+740%)
Mutual labels:  netcore
Excel2Object
excel convert to .NET Object | Excel与.NET 对象进行转换,支持公式、多Sheet等功能
Stars: ✭ 35 (+133.33%)
Mutual labels:  netcore
ChessLib
C# chess library containing a complete data structure and move generation.
Stars: ✭ 37 (+146.67%)
Mutual labels:  netcore
AdventOfCodeBase
Template repository for solving Advent of Code puzzles, which automatically handles input retrieval and output.
Stars: ✭ 33 (+120%)
Mutual labels:  netcore
AlphaVantage.Net
.Net client library for Alpha Vantage API
Stars: ✭ 65 (+333.33%)
Mutual labels:  netcore
tesserae
Components for building h5-based single-page-applications using C#
Stars: ✭ 23 (+53.33%)
Mutual labels:  netcore
comcms
COMCMS_Core 版本
Stars: ✭ 32 (+113.33%)
Mutual labels:  netcore
BackupAssistant
Backup Assistant helps you to backup your files (like database backups or log files) to FTP Server. It works on any platform. ( Windows, Linux and Mac.)
Stars: ✭ 32 (+113.33%)
Mutual labels:  netcore
BetterConsoleTables
Faster, colorable, more configurable, and more robust console colors & tables for C# console applications
Stars: ✭ 59 (+293.33%)
Mutual labels:  netcore
Grpc-MicroService
GRPC based Micro-Service Framework (.net core 2.0)
Stars: ✭ 15 (+0%)
Mutual labels:  netcore
coreipc
WCF-like service model API for communication over named pipes and TCP. .NET and node.js clients.
Stars: ✭ 22 (+46.67%)
Mutual labels:  netcore
PlanningPoker
A demo application of AspNetCore and SignalR
Stars: ✭ 20 (+33.33%)
Mutual labels:  netcore
NModbus4.NetCore
Simply NModbus4 but targeting .NET instead of .NET Framework
Stars: ✭ 25 (+66.67%)
Mutual labels:  netcore
Awesome-Nuget-Packages
📦 A collection of awesome and top .NET packages sorted by most popular needs.
Stars: ✭ 87 (+480%)
Mutual labels:  netcore
fusionauth-netcore-client
The .NET Core client for FusionAuth
Stars: ✭ 18 (+20%)
Mutual labels:  netcore
Decor.NET
A simple way to decorate a class with additional functionality using attributes.
Stars: ✭ 29 (+93.33%)
Mutual labels:  netcore
Tomlet
Zero-Dependency, model-based TOML De/Serializer for .NET
Stars: ✭ 56 (+273.33%)
Mutual labels:  netcore
AsyncVoid
Project related to the site's posts about async void.
Stars: ✭ 32 (+113.33%)
Mutual labels:  netcore
Vaser
Vaser is a powerful high performance event based network engine library for C# .Net. It’s possible to start multiple servers in one program and use the same network code for all servers. In the network communication are all strings are omitted, instead it is based on a unique binary identifier, which the CPU and memory relieves massively.
Stars: ✭ 23 (+53.33%)
Mutual labels:  netcore
dotnet-arangodb
.NET Driver for ArangoDB
Stars: ✭ 52 (+246.67%)
Mutual labels:  netcore

Hosting

Library to simplify the hosting of console applications by making it easier to setup dependency injection, logging and configurations.

Installation

The library is available via NuGet packages:

NuGet Description Version
SimpleSoft.Hosting.Abstractions interfaces and abstract implementations (IHost, IHostBuilder, ...) NuGet
SimpleSoft.Hosting library implementation that typically is only known by the main project NuGet

Package Manager

Install-Package SimpleSoft.Hosting.Abstractions
Install-Package SimpleSoft.Hosting

.NET CLI

dotnet add package SimpleSoft.Hosting.Abstractions
dotnet add package SimpleSoft.Hosting

Packet CLI

paket add package SimpleSoft.Hosting.Abstractions
paket add package SimpleSoft.Hosting

Compatibility

This library is compatible with the following frameworks:

  • SimpleSoft.Hosting.Abstractions
    • .NET Standard 1.1;
  • SimpleSoft.Hosting
    • .NET Framework 4.5.1;
    • .NET Standard 1.3;
    • .NET Standard 1.5;

Usage

Documentation is available via wiki or you can check the working examples or test code.

Here is an example of a console application:

public class Program
{
    private static readonly CancellationTokenSource TokenSource;

    static Program()
    {
        TokenSource = new CancellationTokenSource();
        Console.CancelKeyPress += (sender, eventArgs) =>
        {
            TokenSource.Cancel();
            eventArgs.Cancel = true;
        };
    }

    public static void Main(string[] args) =>
        MainAsync(args, TokenSource.Token).ConfigureAwait(false).GetAwaiter().GetResult();

    private static async Task MainAsync(string[] args, CancellationToken ct)
    {
        var loggerFactory = new LoggerFactory()
            .AddConsole(LogLevel.Trace, true);

        var logger = loggerFactory.CreateLogger<Program>();

        logger.LogInformation("Application started");
        try
        {
            using (var hostBuilder = new HostBuilder("ASPNETCORE_ENVIRONMENT")
                .UseLoggerFactory(loggerFactory)
                .UseStartup<Startup>()
                .ConfigureConfigurationBuilder(p => p.Builder.AddCommandLine(args)))
            {
                await hostBuilder.RunHostAsync<Host>(ct);
            }
        }
        catch (TaskCanceledException)
        {
            logger.LogWarning("Application was terminated by user request");
        }
        catch (Exception e)
        {
            logger.LogCritical(0, e, "Unexpected exception");
        }
        finally
        {
            logger.LogInformation("Application terminated. Press <enter> to exit...");
            Console.ReadLine();
        }
    }

    private class Startup : HostStartup
    {
        public override void ConfigureConfigurationBuilder(IConfigurationBuilderParam param)
        {
            param.Builder
                .SetBasePath(param.Environment.ContentRootPath)
                .AddJsonFile("appsettings.json", true, true)
                .AddJsonFile($"appsettings.{param.Environment.Name}.json", true, true)
                .AddEnvironmentVariables();
        }

        public override IServiceProvider BuildServiceProvider(IServiceProviderBuilderParam param)
        {
            var container = new Autofac.ContainerBuilder();
            container.Populate(param.ServiceCollection);
            return new AutofacServiceProvider(container.Build());
        }
    }

    private class Host : IHost
    {
        private readonly IHostingEnvironment _env;
        private readonly IConfigurationRoot _configurationRoot;
        private readonly ILogger<Host> _logger;

        public Host(IHostingEnvironment env, IConfigurationRoot configurationRoot, ILogger<Host> logger)
        {
            _env = env;
            _configurationRoot = configurationRoot;
            _logger = logger;
        }

        public Task RunAsync(CancellationToken ct)
        {
            _logger.LogDebug("Running host...");

            return Task.CompletedTask;
        }
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].