ProMix0 / Utils

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Utils

Set of my helpers

DI utils

AddTypeAndImplementation

Register service both as TService and TImplementation with transient lifetime

IServiceCollection services = new();
services.AddTypeAndImplementation<IInterface, Service>();

NotEndingBackgroundService

Wrapper for BetterHostedServices.CriticalBackgroundService Allows you to forget about IApplicationEnder

class Service : NotEndingCriticalBackgroundService
{
    protected override Task Execute(CancellationToken token)
    {
        // Do stuff
    }
    
    protected override void OnError(Exception exception)
    {
        // Handle exception
    }
}

Logging utils

LogExceptionMessage

Allows you to fluent log exception before throw it. Default LogLevel is Critical

throw new ArgumentException().LogExceptionMessage(logger);

throw new ArgumentException().LogExceptionMessage(logger, LogLevel.Debug);

Options utils

AddOptions

Overload that take Action for more useful calls chaining

services
.AddOptions<CustomizableField.Configuration>(builder =>
    builder
        .BindConfiguration(CustomizableField.Configuration.SectionName)
        .Validate(CustomizableField.Configuration.Validate))
.AddOptions<AiPlayer.AiPlayerBehaviour>(builder =>
    builder
        .BindConfiguration(AiPlayer.AiPlayerBehaviour.SectionName));

About


Languages

Language:C# 100.0%