Namespace Coree.NETStandard.Abstractions
Classes
DependencySingleton<T>
Represents an abstract base class for creating thread-safe singleton instances with optional dependency injection support. This pattern can be utilized in both dependency injection (DI) and non-DI scenarios. Example usage:
//File ISampleSerivce.cs
public interface ISampleService
{
Task StandardDelayAsync(CancellationToken cancellationToken = default); void StandardDelay();
}
//File DSSampleSerivce.cs
public partial class SampleService : DependencySingleton<SampleService>, ISampleService , IDependencySingleton
{
public SampleService(ILogger<SampleService> logger, IConfiguration configuration) : base(logger, configuration) { }
}
//File SampleSerivce.cs
public partial class SampleService : DependencySingleton<SampleService>, ISampleService , IDependencySingleton
{
public void StandardDelay() { StandardDelayAsync(CancellationToken.None).GetAwaiter().GetResult(); }
public async Task StandardDelayAsync(CancellationToken cancellationToken = default) { await Task.Delay(5000, cancellationToken); }
}
//File Program.cs
static async Task Main(string[] args)
{
SampleService.Instance.SetMinimumLogLevel(LogLevel.Trace);
// The ILogger<SampleService> logger and IConfiguration configuration will be initialized with their own service stacks.
SampleService.Instance.StandardDelay();
// Normal DI usage
var host = Host.CreateDefaultBuilder(args)
.ConfigureLogging((context, logging) => { logging.AddConsole(); logging.AddDebug(); })
.ConfigureServices((context, services) => { services.AddSingleton<ISampleService,SampleService>(); services.AddSingleton<IMyService,MyService>(); });
await host.Build().RunAsync();
}
//Service usage
public class MyService
{
private readonly ISampleService sampleService;
public MyService(ISampleService sampleService)
{
this.sampleService = sampleService;
}
public async Task UseSample()
{
await sampleService.StandardDelayAsync();
}
}
FluentBase
Acts as an abstract foundation for structured error handling in classes using a fluent interface pattern. Offers mechanisms to either immediately throw or accumulate exceptions, alongside managing continuation after validation errors.
Interfaces
IDependencySingleton
Represents an abstract base class for creating thread-safe singleton instances with optional dependency injection support. This pattern can be utilized in both dependency injection (DI) and non-DI scenarios. Example usage:
IFluentBase
Serves as a foundational class for fluent interface pattern error handling, enabling mechanisms for both error accumulation and immediate exception throwing, alongside optional continuation after encountering validation errors. This abstract class standardizes error management for classes utilizing fluent interfaces.