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 InitializationService

Represents an abstract base class for a service that must complete its initialization before other services can start. This service ensures all setup tasks are completed and signals other dependent services when it is safe to begin their processes.

Inheritance
object
InitializationService
Implements
IHostedService
IDisposable
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.InitializationService
Assembly: Coree.NETStandard.dll
Syntax
public abstract class InitializationService : IHostedService, IDisposable
Remarks

Example usage:

services.AddHostedService<MyStartup>();
services.AddHostedService<MyDependend>();

public class MyStartup : InitializationService { private readonly ILogger<MyStartup> _logger; public MyStartup(ILogger<MyStartup> logger) { _logger = logger; }

protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _logger.LogInformation("Start MyStartup"); try { await Task.Delay(5000, stoppingToken); } catch (TaskCanceledException) { _logger.LogInformation("MyStartup was canceled."); return; } _logger.LogInformation("End MyStartup"); } }

public class MyDependend : InitializationDependentServices { private readonly ILogger<MyDependend> _logger; public MyDependend(ILogger<MyDependend> logger) { _logger = logger; }

protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _logger.LogInformation("Start MyDependend"); try { await Task.Delay(5000, stoppingToken); } catch (TaskCanceledException) { _logger.LogInformation("MyDependend was canceled."); return; } _logger.LogInformation("End MyDependend"); } }

Properties

| Edit this page View Source

ExecuteTask

Gets the task that is executing the initialization logic, or null if no task has been started.

Declaration
public virtual Task? ExecuteTask { get; }
Property Value
Type Description
Task

Methods

| Edit this page View Source

Dispose()

Releases all resources used by the service. This method should be called to clean up any resources when the service is no longer needed.

Declaration
public virtual void Dispose()
| Edit this page View Source

ExecuteAsync(CancellationToken)

When overridden in a derived class, executes the initialization logic as an asynchronous operation.

Declaration
protected abstract Task ExecuteAsync(CancellationToken stoppingToken)
Parameters
Type Name Description
CancellationToken stoppingToken

A cancellation token that should be used to request cancellation of the initialization task.

Returns
Type Description
Task

A task that represents the asynchronous initialization operation.

| Edit this page View Source

ReleaseHold()

Signals that the initialization is complete and dependent services can start. This method should be called once the initialization tasks are finished.

Declaration
public static void ReleaseHold()
| Edit this page View Source

StartAsync(CancellationToken)

Starts the service initialization process.

Declaration
public virtual Task StartAsync(CancellationToken cancellationToken)
Parameters
Type Name Description
CancellationToken cancellationToken

A token to monitor for cancellation requests. The cancellation token should cancel the initialization process.

Returns
Type Description
Task

A task that represents the asynchronous operation of starting the service.

| Edit this page View Source

StopAsync(CancellationToken)

Stops the service. This method should cancel the initialization task and ensure the service is properly cleaned up.

Declaration
public virtual Task StopAsync(CancellationToken cancellationToken)
Parameters
Type Name Description
CancellationToken cancellationToken

A token to monitor for cancellation requests. The token should request the service to stop.

Returns
Type Description
Task
| Edit this page View Source

WaitForRelease()

Waits for the initialization to complete. This method blocks until the initialization service signals that it is ready.

Declaration
public static void WaitForRelease()

Implements

IHostedService
IDisposable
  • Edit this page
  • View Source
In this article
Back to top