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 ServiceFactoryEx<T, K, R, S, U, V, W, X, Y, Z>

Represents a generic abstract factory for creating and managing service instances of type T. This factory leverages dependency injection and configuration patterns to facilitate the creation and lifecycle management of services.

Inheritance
object
ServiceFactoryEx<T, K, R, S, U, V, W, X, Y, Z>
ServiceFactoryEx<T>
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>
Implements
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.ServiceFactoryEx
Assembly: Coree.NETStandard.dll
Syntax
public abstract class ServiceFactoryEx<T, K, R, S, U, V, W, X, Y, Z> : IDisposable where T : class where K : class where R : class where S : class where U : class where V : class where W : class where X : class where Y : class where Z : class
Type Parameters
Name Description
T

The type of service to be created and managed. This type must be a class that implements IDisposable.

K

Additional service type managed by this factory.

R

Additional service type managed by this factory.

S

Additional service type managed by this factory.

U

Additional service type managed by this factory.

V

Additional service type managed by this factory.

W

Additional service type managed by this factory.

X

Additional service type managed by this factory.

Y

Additional service type managed by this factory.

Z

Additional service type managed by this factory.

Remarks

The ServiceFactoryEx<T, K, R, S, U, V, W, X, Y, Z> serves as a foundational component in applications requiring robust and configurable service instantiation. It abstracts the complexity involved in the instantiation and management of services, thereby promoting a clean and maintainable architecture. This class should be inherited by specific service factory implementations that can provide concrete and custom instantiation logic. The following example shows how to use the FileService in a console application:

private static async Task Main(string[] args)
{
    // Creating a FileService instance without params nullable ILogger.
    var fileService1 = new FileService();
    // Creating a FileService instance using the constructor that accepts an ILogger.
    var fileService2 = new FileService(new Logger<FileService>());
    // Creating a FileService instance using the factory method.
    var fileService3 = FileService.CreateServiceFactory();

    // Example method calls on fileService instances
    await fileService1.SomeFileOperationAsync();
    await fileService2.SomeFileOperationAsync();
    fileService3.SomeFileOperation();
}

public partial class FileService : ServiceFactoryEx<FileService>, IFileService
{
   private readonly ILogger<FileService>? _logger;
   public FileService(ILogger< FileService>? logger = null)
   {
      this._logger = logger;
   }
}

Methods

| Edit this page View Source

CreateServiceFactory()

Creates a service instance with a default logging level set to Trace.

Declaration
public static T CreateServiceFactory()
Returns
Type Description
T

A new instance of type T with default logging configuration.

Remarks

This method simplifies the creation of a service instance by applying a default Trace logging level. It delegates to another factory method, providing a standardized logging setup for basic tracing of application activities.

| Edit this page View Source

CreateServiceFactory(LogLevel)

Creates a service instance with a default logging level.

Declaration
public static T CreateServiceFactory(LogLevel logLevel)
Parameters
Type Name Description
LogLevel logLevel

The logging level to be used as default.

Returns
Type Description
T

A new instance of type T.

| Edit this page View Source

CreateServiceFactory(Action<IServiceCollection>?)

Creates a service instance with optional service collection configuration.

Declaration
public static T CreateServiceFactory(Action<IServiceCollection>? services = null)
Parameters
Type Name Description
Action<IServiceCollection> services

An action to configure the services. Can be null.

Returns
Type Description
T

A new instance of type T.

| Edit this page View Source

CreateServiceFactory(Action<IServiceCollection>?, Action<ILoggingBuilder>?, Action<IHostBuilder>?)

Creates a service instance with optional configurations for services, logging, and host.

Declaration
public static T CreateServiceFactory(Action<IServiceCollection>? configureServices = null, Action<ILoggingBuilder>? configureLogging = null, Action<IHostBuilder>? configureHost = null)
Parameters
Type Name Description
Action<IServiceCollection> configureServices

An action to configure the services. Can be null.

Action<ILoggingBuilder> configureLogging

An action to configure the logging. Can be null.

Action<IHostBuilder> configureHost

An action to configure the host. Can be null.

Returns
Type Description
T

A new instance of type T.

| Edit this page View Source

CreateServiceFactory(Action<IHostBuilder>?)

Creates a service instance with optional host configuration.

Declaration
public static T CreateServiceFactory(Action<IHostBuilder>? configureHost = null)
Parameters
Type Name Description
Action<IHostBuilder> configureHost

An action to configure the host. Can be null.

Returns
Type Description
T

A new instance of type T.

| Edit this page View Source

Dispose()

Disposes the static instance of the host if it has been created.

Declaration
public void Dispose()

Implements

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