Coree.NETStandard
  • API
Show / Hide Table of Contents
  • Coree.NETStandard.Abstractions.DependencySingleton
    • DependencySingleton<T>
    • IDependencySingleton
  • Coree.NETStandard.Abstractions.FluentBase
    • FluentBase
    • IFluentBase
  • Coree.NETStandard.Abstractions.InitializationService
    • InitializationDependentServices
    • InitializationService
  • Coree.NETStandard.Abstractions.ServiceFactory
    • ServiceFactory<T>
  • Coree.NETStandard.Abstractions.ServiceFactoryEx
    • ServiceFactoryEx<T>
    • ServiceFactoryEx<T, K, R, S, U, V, W, X, Y, Z>
    • ServiceFactoryEx<T, K>
    • ServiceFactoryEx<T, K, R>
    • ServiceFactoryEx<T, K, R, S>
    • ServiceFactoryEx<T, K, R, S, U>
    • ServiceFactoryEx<T, K, R, S, U, V>
    • ServiceFactoryEx<T, K, R, S, U, V, W>
    • ServiceFactoryEx<T, K, R, S, U, V, W, X>
    • ServiceFactoryEx<T, K, R, S, U, V, W, X, Y>
  • Coree.NETStandard.Classes.AsyncEventCollection
    • AsyncEventCollection<T>
    • AsyncEventCollection<T>.CustomEventDelegate
  • Coree.NETStandard.Classes.CommonDistinguishedNameBuilder
    • CommonDistinguishedNameBuilder
    • DistinguishedName
  • Coree.NETStandard.Classes.Criteria
    • CriteriaComparisonMethod
    • CriteriaEnumerableExtensions
    • CriteriaExpressionBuilder
    • CriteriaItem<TValue>
    • CriteriaItems
    • CriteriaOperator
    • CriteriaQueryableExtensions
  • Coree.NETStandard.Classes.HttpRequestService
    • ContentComposer
    • HttpRequestHeadersExtensions
    • HttpRequestService
    • HttpRequestServiceHandler
    • HttpRequestServiceUriExtensions
    • ServiceCollectionExtensions
    • TransactionRecord
  • Coree.NETStandard.Classes.Scheduler
    • Scheduler
    • Scheduler.TickerEventArgs
    • Scheduler.TickerEventDelegate
  • Coree.NETStandard.Classes.ThreadSafeCollection
    • ThreadSafeCollection<T>
  • Coree.NETStandard.Classes.ThreadSafeValue
    • ThreadSafeValue<T>
  • Coree.NETStandard.Classes.TimeOfDay
    • TimeOfDay
  • Coree.NETStandard.Extensions.Collections.Enumerable
    • CollectionsEnumerableExtensions
  • Coree.NETStandard.Extensions.Collections.List
    • CollectionsListExtensions
  • Coree.NETStandard.Extensions.Conversions.ByteArray
    • ConversionsByteArrayExtensions
  • Coree.NETStandard.Extensions.Conversions.HostApplicationBuilder
    • ConversionsHostApplicationBuilderExtensions
  • Coree.NETStandard.Extensions.Conversions.String
    • ConversionsStringExtensions
    • Encodings
  • Coree.NETStandard.Extensions.Conversions.Stringbuilder
    • ConversionsStringbuilderExtension
  • Coree.NETStandard.Extensions.Enums
    • EnumExtensions
  • Coree.NETStandard.Extensions.Http.HttpHeader
    • HttpHeadersExtensions
  • Coree.NETStandard.Extensions.Primitives.Bool
    • PrimitivesBoolExtensions
  • Coree.NETStandard.Extensions.Reflection.ServiceProvider
    • ReflectionServiceProviderExtensions
  • Coree.NETStandard.Extensions.ServiceCollection
    • ServiceCollectionExtensions
  • Coree.NETStandard.Extensions.Threading.CancellationToken
    • ThreadingCancellationTokenExtensions
  • Coree.NETStandard.Extensions.Utilities
    • DateTimeExtensions
  • Coree.NETStandard.Extensions.Validations.String
    • ValidationsStringExtensions
  • Coree.NETStandard.HostedServicesCollection
    • HostedServicesCollectionConfig<T>
    • IHostedServicesCollectionConfig<T>
    • ServiceCollectionExtensions
    • ServiceProviderExtensions
  • Coree.NETStandard.Serilog
    • ConditionalLevelSink
    • CustomTheme
    • LoggerSinkConfigurationExtensions
    • OutputTemplates
    • ServiceCollectionExtensions
    • SourceContextShortEnricher
  • Coree.NETStandard.Services.DebugManagement
    • DebugService
    • IDebugService
  • Coree.NETStandard.Services.DirectoryOperationsManagement
    • DirectoryOperationsService
    • IDirectoryOperationsService
  • Coree.NETStandard.Services.FileManagement
    • FileService
    • IFileService
  • Coree.NETStandard.Services.FileOperationsManagement
    • FileOperationsService
    • FileOperationsService.FileSystemEntry
    • FileOperationsService.FileSystemInformation
    • FileOperationsService.VerifiedCopyStatus
    • IFileOperationsService
  • Coree.NETStandard.Services.HashManagement
    • HashService
    • IHashService
  • Coree.NETStandard.Services.NetworkManagement
    • INetworkService
    • NetworkService
    • NetworkService.IpAdressInformation
    • NetworkService.NetworkInterfaceDetail
  • Coree.NETStandard.Services.ProcessManagement
    • IProcessService
    • ProcessRunExitCodeState
    • ProcessRunResult
    • ProcessService
  • Coree.NETStandard.Services.RuntimeInsightsManagement
    • IRuntimeInsightsService
    • RuntimeInsightsService
  • Coree.NETStandard.SpectreConsole
    • CommandAppExtensions
    • HostBuilderExtensions
    • ServiceCollectionExtensions
    • SpectreConsoleHostedService
    • SpectreConsoleHostedService.ExitCode
    • SpectreConsoleTypeRegistrar
    • SpectreConsoleTypeResolver
  • Coree.NETStandard.UnderConstruction
    • DbContextExtensions
    • HttpClientStatic
    • HttpClientStatic.HttpClientResponse
    • HttpClientStatic.XRate
    • HttpClientStatic.XRateGroup
    • HttpClientStatic.XRateItem
    • IScheduleProvider
    • IntervalScheduleProvider
    • LimitedHistory<T>
    • ScheduleCombiner
    • Scheduler
    • Scheduler.TickerEventArgs
    • Scheduler.TickerEventDelegate
    • Scheduler2
    • Scheduler2.TickerEventArgs
    • Scheduler2.TickerEventDelegate
    • Scheduler3
    • Scheduler3.TickerEventArgs
    • Scheduler3.TickerEventDelegate
    • SqlliteMemoryContext
    • SqlliteMemoryContext.UserDataDto
    • TimedEntry<T>
    • Timing
    • Timing.Ticker
    • Timing.Ticker.TickerEventArgs
    • Timing.TickerSync
    • WeekDayAtScheduleProvider
  • Coree.NETStandard.Utilities
    • EventSubscription
    • MainContext

Class 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();
     }
}
Inheritance
object
DependencySingleton<T>
Implements
IDependencySingleton
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Coree.NETStandard.Abstractions.DependencySingleton
Assembly: Coree.NETStandard.dll
Syntax
[Obsolete("DependencySingleton<T> is deprecated and will be removed in future versions. Use ServiceFactoryEx<T> instead.")]
public abstract class DependencySingleton<T> : IDependencySingleton
Type Parameters
Name Description
T

The type of the singleton instance.

Constructors

| Edit this page View Source

DependencySingleton(ILogger<T>, IConfiguration)

Initializes a new instance of the DependencySingleton<T> class with the specified logger and configuration services.

Declaration
protected DependencySingleton(ILogger<T> logger, IConfiguration configuration)
Parameters
Type Name Description
ILogger<T> logger

The logger service.

IConfiguration configuration

The configuration service.

Fields

| Edit this page View Source

configuration

Represents the configuration for the application. This encompasses settings from various configuration sources (e.g., appsettings.json, environment variables) and is used to access DependencySingleton settings such as connection strings, feature toggles, and other configurable aspects of the application.

Declaration
protected readonly IConfiguration configuration
Field Value
Type Description
IConfiguration
| Edit this page View Source

logger

Provides logging capabilities for the singleton instance. By default, the logger's minimum logging level is set to Trace, allowing all log messages to be captured. However, the default filter level applied to log messages is set to Information, meaning that only logs at Information level or higher will be emitted unless otherwise adjusted. The logging level filter can be dynamically changed at runtime using the SetLogLevelFilter(LogLevel) method to control the verbosity of the logging output.

Declaration
protected readonly ILogger<T> logger
Field Value
Type Description
ILogger<T>

Properties

| Edit this page View Source

Instance

Gets the singleton instance of the class, ensuring thread safety.

Declaration
public static T Instance { get; }
Property Value
Type Description
T

The singleton instance of type T, which is the specific implementation of the DependencySingleton<T>. Type T represents the derived singleton class that includes implementations for required services such as logging and configuration. The instance is initialized with these services upon the first request, adhering to the singleton pattern to ensure only one instance is created and shared throughout the application.

Methods

| Edit this page View Source

SetLogLevelFilter(LogLevel)

Sets the minimum log level filter for the application. This level acts as a filter for the logs that are emitted. Logs below this level will not be emitted. Default is Information

Declaration
public void SetLogLevelFilter(LogLevel logLevel = LogLevel.Information)
Parameters
Type Name Description
LogLevel logLevel

The log level to set as the minimum threshold for logging.

Implements

IDependencySingleton
  • Edit this page
  • View Source
In this article
Back to top