Class ServiceFactoryEx<T, K>
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
Implements
Inherited Members
Namespace: Coree.NETStandard.Abstractions.ServiceFactoryEx
Assembly: Coree.NETStandard.dll
Syntax
public abstract class ServiceFactoryEx<T, K> : ServiceFactoryEx<T, K, object, object, object, object, object, object, object, object>, IDisposable where T : class where K : 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. |
Remarks
The ServiceFactoryEx<T, K> 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.
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;
}
}