* quickfix

This commit is contained in:
2025-08-08 17:30:17 +04:00
parent cee7ed3adc
commit 0cf8ea27b6
2 changed files with 171 additions and 207 deletions
@@ -36,7 +36,7 @@ namespace Telegrator.Attributes.Components
public int Priority { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to form a fallback report for debugging purposes.
/// Gets or sets a value indicating whether to form a fallback report.
/// </summary>
public bool FormReport { get; set; }
@@ -20,12 +20,12 @@ namespace Telegrator.MadiatorCore.Descriptors
/// Keyed handler descriptor (uses a service key).
/// </summary>
Keyed,
/// <summary>
/// Implicit handler descriptor.
/// </summary>
Implicit,
/// <summary>
/// Singleton handler descriptor (single instance).
/// </summary>
@@ -74,7 +74,7 @@ namespace Telegrator.MadiatorCore.Descriptors
}
/// <summary>
/// Gets or sets a value indicating whether to form a fallback report for debugging purposes.
/// Gets or sets a value indicating whether to form a fallback report.
/// </summary>
public bool FormReport
{
@@ -129,8 +129,7 @@ namespace Telegrator.MadiatorCore.Descriptors
}
/// <summary>
/// Gets or sets the display string for this handler descriptor.
/// Used for debugging and logging purposes.
/// Display string for the handler (for debugging or logging).
/// </summary>
public string? DisplayString
{
@@ -139,8 +138,7 @@ namespace Telegrator.MadiatorCore.Descriptors
}
/// <summary>
/// Gets or sets the lazy initialization action for this handler.
/// Called when the handler instance needs to be initialized.
/// Gets or sets a function for 'lazy' handlers initialization
/// </summary>
public Action<UpdateHandlerBase>? LazyInitialization
{
@@ -149,60 +147,56 @@ namespace Telegrator.MadiatorCore.Descriptors
}
/// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class.
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with the specified descriptor type and handler type.
/// Automatically inspects the handler type to extract attributes, filters, and configuration.
/// </summary>
/// <param name="descriptorType">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler.</param>
/// <param name="dontInspect">Whether to skip inspection of the handler type.</param>
/// <param name="descriptorType">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler to describe</param>
/// <param name="dontInspect"></param>
/// <exception cref="ArgumentException">Thrown when the handler type is not compatible with the expected handler type</exception>
public HandlerDescriptor(DescriptorType descriptorType, Type handlerType, bool dontInspect = false)
{
Type = descriptorType;
HandlerType = handlerType;
Indexer = new DescriptorIndexer(0, 0, 0);
Filters = new DescriptorFiltersSet(null, null, null);
if (!dontInspect)
{
UpdateHandlerAttributeBase? pollingHandlerAttribute = HandlerInspector.GetPollingHandlerAttribute(handlerType);
if (pollingHandlerAttribute != null)
{
UpdateType = pollingHandlerAttribute.Type;
Indexer = pollingHandlerAttribute.GetIndexer();
}
if (dontInspect)
return;
IFilter<Update>[]? filters = HandlerInspector.GetFilterAttributes(handlerType, UpdateType).ToArray();
IFilter<Update>? stateKeepFilter = HandlerInspector.GetStateKeeperAttribute(handlerType);
DescriptorAspectsSet? aspects = HandlerInspector.GetAspects(handlerType);
UpdateHandlerAttributeBase handlerAttribute = HandlerInspector.GetHandlerAttribute(handlerType);
if (handlerAttribute.ExpectingHandlerType != null && !handlerAttribute.ExpectingHandlerType.Contains(handlerType.BaseType))
throw new ArgumentException(string.Format("This handler attribute cannot be attached to this class. Attribute can be attached on next handlers : {0}", string.Join(", ", handlerAttribute.ExpectingHandlerType.AsEnumerable())));
if (filters.Length > 0 || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter);
}
StateKeeperAttributeBase? stateKeeperAttribute = HandlerInspector.GetStateKeeperAttribute(handlerType);
IFilter<Update>[] filters = HandlerInspector.GetFilterAttributes(handlerType, handlerAttribute.Type).ToArray();
if (aspects != null)
{
Aspects = aspects;
}
}
UpdateType = handlerAttribute.Type;
Indexer = handlerAttribute.GetIndexer();
FormReport = handlerAttribute.FormReport;
Filters = new DescriptorFiltersSet(handlerAttribute, stateKeeperAttribute, filters);
Aspects = HandlerInspector.GetAspects(handlerType);
DisplayString = HandlerInspector.GetDisplayName(handlerType);
}
/// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class for keyed handlers.
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class as a keyed handler with the specified service key.
/// </summary>
/// <param name="handlerType">The type of the handler.</param>
/// <param name="serviceKey">The service key for the handler.</param>
/// <param name="handlerType">The type of the handler to describe</param>
/// <param name="serviceKey">The service key for dependency injection</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="serviceKey"/> is null</exception>
public HandlerDescriptor(Type handlerType, object serviceKey) : this(DescriptorType.Keyed, handlerType)
{
ServiceKey = serviceKey;
ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey));
}
/// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with complete configuration.
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with all basic properties.
/// </summary>
/// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler.</param>
/// <param name="updateType">The update type handled by this handler.</param>
/// <param name="indexer">The indexer for handler concurrency and priority.</param>
/// <param name="filters">The set of filters associated with this handler.</param>
/// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler</param>
/// <param name="updateType">The type of update this handler processes</param>
/// <param name="indexer">The indexer for handler concurrency and priority</param>
/// <param name="filters">The set of filters associated with this handler</param>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters)
{
Type = type;
@@ -213,15 +207,16 @@ namespace Telegrator.MadiatorCore.Descriptors
}
/// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class for singleton handlers.
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with singleton instance support.
/// </summary>
/// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler.</param>
/// <param name="updateType">The update type handled by this handler.</param>
/// <param name="indexer">The indexer for handler concurrency and priority.</param>
/// <param name="filters">The set of filters associated with this handler.</param>
/// <param name="serviceKey">The service key for the handler.</param>
/// <param name="singletonInstance">The singleton instance of the handler.</param>
/// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler</param>
/// <param name="updateType">The type of update this handler processes</param>
/// <param name="indexer">The indexer for handler concurrency and priority</param>
/// <param name="filters">The set of filters associated with this handler</param>
/// <param name="serviceKey">The service key for dependency injection</param>
/// <param name="singletonInstance">The singleton instance of the handler</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="serviceKey"/> or <paramref name="singletonInstance"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters, object serviceKey, UpdateHandlerBase singletonInstance)
{
Type = type;
@@ -229,19 +224,20 @@ namespace Telegrator.MadiatorCore.Descriptors
UpdateType = updateType;
Indexer = indexer;
Filters = filters;
ServiceKey = serviceKey;
SingletonInstance = singletonInstance;
ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey));
SingletonInstance = singletonInstance ?? throw new ArgumentNullException(nameof(singletonInstance));
}
/// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with instance factory.
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with instance factory support.
/// </summary>
/// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler.</param>
/// <param name="updateType">The update type handled by this handler.</param>
/// <param name="indexer">The indexer for handler concurrency and priority.</param>
/// <param name="filters">The set of filters associated with this handler.</param>
/// <param name="instanceFactory">The factory for creating handler instances.</param>
/// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler</param>
/// <param name="updateType">The type of update this handler processes</param>
/// <param name="indexer">The indexer for handler concurrency and priority</param>
/// <param name="filters">The set of filters associated with this handler</param>
/// <param name="instanceFactory">Factory for creating handler instances</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="instanceFactory"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters, Func<UpdateHandlerBase> instanceFactory)
{
Type = type;
@@ -249,19 +245,20 @@ namespace Telegrator.MadiatorCore.Descriptors
UpdateType = updateType;
Indexer = indexer;
Filters = filters;
InstanceFactory = instanceFactory;
InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
}
/// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with service key and instance factory.
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with service key and instance factory support.
/// </summary>
/// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler.</param>
/// <param name="updateType">The update type handled by this handler.</param>
/// <param name="indexer">The indexer for handler concurrency and priority.</param>
/// <param name="filters">The set of filters associated with this handler.</param>
/// <param name="serviceKey">The service key for the handler.</param>
/// <param name="instanceFactory">The factory for creating handler instances.</param>
/// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler</param>
/// <param name="updateType">The type of update this handler processes</param>
/// <param name="indexer">The indexer for handler concurrency and priority</param>
/// <param name="filters">The set of filters associated with this handler</param>
/// <param name="serviceKey">The service key for dependency injection</param>
/// <param name="instanceFactory">Factory for creating handler instances</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="serviceKey"/> or <paramref name="instanceFactory"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters, object serviceKey, Func<UpdateHandlerBase> instanceFactory)
{
Type = type;
@@ -269,243 +266,210 @@ namespace Telegrator.MadiatorCore.Descriptors
UpdateType = updateType;
Indexer = indexer;
Filters = filters;
ServiceKey = serviceKey;
InstanceFactory = instanceFactory;
ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey));
InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
}
/// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with polling handler attribute.
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with polling handler attribute and filters.
/// </summary>
/// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler.</param>
/// <param name="pollingHandlerAttribute">The polling handler attribute.</param>
/// <param name="filters">The array of filters associated with this handler.</param>
/// <param name="stateKeepFilter">The state keeper filter.</param>
/// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler</param>
/// <param name="pollingHandlerAttribute">The polling handler attribute containing configuration</param>
/// <param name="filters">Optional array of filters to apply</param>
/// <param name="stateKeepFilter">Optional state keeping filter</param>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter)
{
Type = type;
HandlerType = handlerType;
UpdateType = pollingHandlerAttribute.Type;
Indexer = pollingHandlerAttribute.GetIndexer();
FormReport = pollingHandlerAttribute.FormReport;
if (filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter);
}
Filters = new DescriptorFiltersSet(pollingHandlerAttribute, stateKeepFilter, filters);
}
/// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class for singleton handlers with polling handler attribute.
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with polling handler attribute, filters, and singleton instance.
/// </summary>
/// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler.</param>
/// <param name="pollingHandlerAttribute">The polling handler attribute.</param>
/// <param name="filters">The array of filters associated with this handler.</param>
/// <param name="stateKeepFilter">The state keeper filter.</param>
/// <param name="serviceKey">The service key for the handler.</param>
/// <param name="singletonInstance">The singleton instance of the handler.</param>
/// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler</param>
/// <param name="pollingHandlerAttribute">The polling handler attribute containing configuration</param>
/// <param name="filters">Optional array of filters to apply</param>
/// <param name="stateKeepFilter">Optional state keeping filter</param>
/// <param name="serviceKey">The service key for dependency injection</param>
/// <param name="singletonInstance">The singleton instance of the handler</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="serviceKey"/> or <paramref name="singletonInstance"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, object serviceKey, UpdateHandlerBase singletonInstance)
{
Type = type;
HandlerType = handlerType;
UpdateType = pollingHandlerAttribute.Type;
Indexer = pollingHandlerAttribute.GetIndexer();
FormReport = pollingHandlerAttribute.FormReport;
ServiceKey = serviceKey;
SingletonInstance = singletonInstance;
if (filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter);
}
Filters = new DescriptorFiltersSet(pollingHandlerAttribute, stateKeepFilter, filters);
ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey));
SingletonInstance = singletonInstance ?? throw new ArgumentNullException(nameof(singletonInstance));
}
/// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with instance factory and polling handler attribute.
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with polling handler attribute, filters, and instance factory.
/// </summary>
/// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler.</param>
/// <param name="pollingHandlerAttribute">The polling handler attribute.</param>
/// <param name="filters">The array of filters associated with this handler.</param>
/// <param name="stateKeepFilter">The state keeper filter.</param>
/// <param name="instanceFactory">The factory for creating handler instances.</param>
/// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler</param>
/// <param name="pollingHandlerAttribute">The polling handler attribute containing configuration</param>
/// <param name="filters">Optional array of filters to apply</param>
/// <param name="stateKeepFilter">Optional state keeping filter</param>
/// <param name="instanceFactory">Factory for creating handler instances</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="instanceFactory"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, Func<UpdateHandlerBase> instanceFactory)
{
Type = type;
HandlerType = handlerType;
UpdateType = pollingHandlerAttribute.Type;
Indexer = pollingHandlerAttribute.GetIndexer();
FormReport = pollingHandlerAttribute.FormReport;
InstanceFactory = instanceFactory;
if (filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter);
}
Filters = new DescriptorFiltersSet(pollingHandlerAttribute, stateKeepFilter, filters);
InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
}
/// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with service key, instance factory and polling handler attribute.
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with polling handler attribute, filters, service key, and instance factory.
/// </summary>
/// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler.</param>
/// <param name="pollingHandlerAttribute">The polling handler attribute.</param>
/// <param name="filters">The array of filters associated with this handler.</param>
/// <param name="stateKeepFilter">The state keeper filter.</param>
/// <param name="serviceKey">The service key for the handler.</param>
/// <param name="instanceFactory">The factory for creating handler instances.</param>
/// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler</param>
/// <param name="pollingHandlerAttribute">The polling handler attribute containing configuration</param>
/// <param name="filters">Optional array of filters to apply</param>
/// <param name="stateKeepFilter">Optional state keeping filter</param>
/// <param name="serviceKey">The service key for dependency injection</param>
/// <param name="instanceFactory">Factory for creating handler instances</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="serviceKey"/> or <paramref name="instanceFactory"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, object serviceKey, Func<UpdateHandlerBase> instanceFactory)
{
Type = type;
HandlerType = handlerType;
UpdateType = pollingHandlerAttribute.Type;
Indexer = pollingHandlerAttribute.GetIndexer();
FormReport = pollingHandlerAttribute.FormReport;
ServiceKey = serviceKey;
InstanceFactory = instanceFactory;
if (filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter);
}
Filters = new DescriptorFiltersSet(pollingHandlerAttribute, stateKeepFilter, filters);
ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey));
InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
}
/// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with complete configuration.
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with validation filter support.
/// </summary>
/// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler.</param>
/// <param name="updateType">The update type handled by this handler.</param>
/// <param name="indexer">The indexer for handler concurrency and priority.</param>
/// <param name="validateFilter">The validation filter.</param>
/// <param name="filters">The array of filters associated with this handler.</param>
/// <param name="stateKeepFilter">The state keeper filter.</param>
/// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler</param>
/// <param name="updateType">The type of update this handler processes</param>
/// <param name="indexer">The indexer for handler concurrency and priority</param>
/// <param name="validateFilter">Optional validation filter</param>
/// <param name="filters">Optional array of filters to apply</param>
/// <param name="stateKeepFilter">Optional state keeping filter</param>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, IFilter<Update>? validateFilter, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter)
{
Type = type;
HandlerType = handlerType;
UpdateType = updateType;
Indexer = indexer;
if (validateFilter != null || filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter, validateFilter);
}
Filters = new DescriptorFiltersSet(validateFilter, stateKeepFilter, filters);
}
/// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class for singleton handlers with complete configuration.
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with validation filter and singleton instance support.
/// </summary>
/// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler.</param>
/// <param name="updateType">The update type handled by this handler.</param>
/// <param name="indexer">The indexer for handler concurrency and priority.</param>
/// <param name="validateFilter">The validation filter.</param>
/// <param name="filters">The array of filters associated with this handler.</param>
/// <param name="stateKeepFilter">The state keeper filter.</param>
/// <param name="serviceKey">The service key for the handler.</param>
/// <param name="singletonInstance">The singleton instance of the handler.</param>
/// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler</param>
/// <param name="updateType">The type of update this handler processes</param>
/// <param name="indexer">The indexer for handler concurrency and priority</param>
/// <param name="validateFilter">Optional validation filter</param>
/// <param name="filters">Optional array of filters to apply</param>
/// <param name="stateKeepFilter">Optional state keeping filter</param>
/// <param name="serviceKey">The service key for dependency injection</param>
/// <param name="singletonInstance">The singleton instance of the handler</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="serviceKey"/> or <paramref name="singletonInstance"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, IFilter<Update>? validateFilter, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, object serviceKey, UpdateHandlerBase singletonInstance)
{
Type = type;
HandlerType = handlerType;
UpdateType = updateType;
Indexer = indexer;
ServiceKey = serviceKey;
SingletonInstance = singletonInstance;
if (validateFilter != null || filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter, validateFilter);
}
Filters = new DescriptorFiltersSet(validateFilter, stateKeepFilter, filters);
ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey));
SingletonInstance = singletonInstance ?? throw new ArgumentNullException(nameof(singletonInstance));
}
/// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with instance factory and complete configuration.
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with validation filter and instance factory support.
/// </summary>
/// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler.</param>
/// <param name="updateType">The update type handled by this handler.</param>
/// <param name="indexer">The indexer for handler concurrency and priority.</param>
/// <param name="validateFilter">The validation filter.</param>
/// <param name="filters">The array of filters associated with this handler.</param>
/// <param name="stateKeepFilter">The state keeper filter.</param>
/// <param name="instanceFactory">The factory for creating handler instances.</param>
/// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler</param>
/// <param name="updateType">The type of update this handler processes</param>
/// <param name="indexer">The indexer for handler concurrency and priority</param>
/// <param name="validateFilter">Optional validation filter</param>
/// <param name="filters">Optional array of filters to apply</param>
/// <param name="stateKeepFilter">Optional state keeping filter</param>
/// <param name="instanceFactory">Factory for creating handler instances</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="instanceFactory"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, IFilter<Update>? validateFilter, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, Func<UpdateHandlerBase> instanceFactory)
{
Type = type;
HandlerType = handlerType;
UpdateType = updateType;
Indexer = indexer;
InstanceFactory = instanceFactory;
if (validateFilter != null || filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter, validateFilter);
}
Filters = new DescriptorFiltersSet(validateFilter, stateKeepFilter, filters);
InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
}
/// <summary>
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with service key, instance factory and complete configuration.
/// Initializes a new instance of the <see cref="HandlerDescriptor"/> class with validation filter, service key, and instance factory support.
/// </summary>
/// <param name="type">The type of the descriptor.</param>
/// <param name="handlerType">The type of the handler.</param>
/// <param name="updateType">The update type handled by this handler.</param>
/// <param name="indexer">The indexer for handler concurrency and priority.</param>
/// <param name="validateFilter">The validation filter.</param>
/// <param name="filters">The array of filters associated with this handler.</param>
/// <param name="stateKeepFilter">The state keeper filter.</param>
/// <param name="serviceKey">The service key for the handler.</param>
/// <param name="instanceFactory">The factory for creating handler instances.</param>
/// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler</param>
/// <param name="updateType">The type of update this handler processes</param>
/// <param name="indexer">The indexer for handler concurrency and priority</param>
/// <param name="validateFilter">Optional validation filter</param>
/// <param name="filters">Optional array of filters to apply</param>
/// <param name="stateKeepFilter">Optional state keeping filter</param>
/// <param name="serviceKey">The service key for dependency injection</param>
/// <param name="instanceFactory">Factory for creating handler instances</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="serviceKey"/> or <paramref name="instanceFactory"/> is null</exception>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, IFilter<Update>? validateFilter, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, object serviceKey, Func<UpdateHandlerBase> instanceFactory)
{
Type = type;
HandlerType = handlerType;
UpdateType = updateType;
Indexer = indexer;
ServiceKey = serviceKey;
InstanceFactory = instanceFactory;
if (validateFilter != null || filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter, validateFilter);
}
Filters = new DescriptorFiltersSet(validateFilter, stateKeepFilter, filters);
ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey));
InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
}
/// <summary>
/// Sets the singleton instance for this handler descriptor.
/// Sets singleton instance of this descriptor
/// Throws exception if instance already set
/// </summary>
/// <param name="instance">The singleton instance to set.</param>
/// <param name="instance"></param>
/// <exception cref="Exception"></exception>
public void SetInstance(UpdateHandlerBase instance)
{
if (Type != DescriptorType.Singleton)
throw new InvalidOperationException("Cannot set instance for non-singleton descriptor");
if (SingletonInstance != null)
throw new Exception();
SingletonInstance = instance;
}
/// <summary>
/// Attempts to set the singleton instance for this handler descriptor.
/// Tries to set singleton instance of this descriptor
/// </summary>
/// <param name="instance">The singleton instance to set.</param>
/// <returns>True if the instance was set successfully; otherwise, false.</returns>
/// <param name="instance"></param>
/// <returns></returns>
public bool TrySetInstance(UpdateHandlerBase instance)
{
if (Type != DescriptorType.Singleton)
if (SingletonInstance != null)
return false;
SingletonInstance = instance;
return true;
}
/// <summary>
/// Returns a string representation of this handler descriptor.
/// </summary>
/// <returns>A string representation of the handler descriptor.</returns>
/// <inheritdoc/>
public override string ToString()
{
return DisplayString ?? $"{Type} {HandlerType.Name}";
}
=> DisplayString ?? HandlerType.Name;
}
}
}