Set of my helpers
Register service both as TService and TImplementation with transient
lifetime
IServiceCollection services = new();
services.AddTypeAndImplementation<IInterface, Service>();
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
}
}
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);
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));