* 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; } public int Priority { get; set; }
/// <summary> /// <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> /// </summary>
public bool FormReport { get; set; } public bool FormReport { get; set; }
@@ -74,7 +74,7 @@ namespace Telegrator.MadiatorCore.Descriptors
} }
/// <summary> /// <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> /// </summary>
public bool FormReport public bool FormReport
{ {
@@ -129,8 +129,7 @@ namespace Telegrator.MadiatorCore.Descriptors
} }
/// <summary> /// <summary>
/// Gets or sets the display string for this handler descriptor. /// Display string for the handler (for debugging or logging).
/// Used for debugging and logging purposes.
/// </summary> /// </summary>
public string? DisplayString public string? DisplayString
{ {
@@ -139,8 +138,7 @@ namespace Telegrator.MadiatorCore.Descriptors
} }
/// <summary> /// <summary>
/// Gets or sets the lazy initialization action for this handler. /// Gets or sets a function for 'lazy' handlers initialization
/// Called when the handler instance needs to be initialized.
/// </summary> /// </summary>
public Action<UpdateHandlerBase>? LazyInitialization public Action<UpdateHandlerBase>? LazyInitialization
{ {
@@ -149,60 +147,56 @@ namespace Telegrator.MadiatorCore.Descriptors
} }
/// <summary> /// <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> /// </summary>
/// <param name="descriptorType">The type of the descriptor.</param> /// <param name="descriptorType">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler.</param> /// <param name="handlerType">The type of the handler to describe</param>
/// <param name="dontInspect">Whether to skip inspection of the handler type.</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) public HandlerDescriptor(DescriptorType descriptorType, Type handlerType, bool dontInspect = false)
{ {
Type = descriptorType; Type = descriptorType;
HandlerType = handlerType; HandlerType = handlerType;
Indexer = new DescriptorIndexer(0, 0, 0); Filters = new DescriptorFiltersSet(null, null, null);
if (!dontInspect) if (dontInspect)
{ return;
UpdateHandlerAttributeBase? pollingHandlerAttribute = HandlerInspector.GetPollingHandlerAttribute(handlerType);
if (pollingHandlerAttribute != null)
{
UpdateType = pollingHandlerAttribute.Type;
Indexer = pollingHandlerAttribute.GetIndexer();
}
IFilter<Update>[]? filters = HandlerInspector.GetFilterAttributes(handlerType, UpdateType).ToArray(); UpdateHandlerAttributeBase handlerAttribute = HandlerInspector.GetHandlerAttribute(handlerType);
IFilter<Update>? stateKeepFilter = HandlerInspector.GetStateKeeperAttribute(handlerType); if (handlerAttribute.ExpectingHandlerType != null && !handlerAttribute.ExpectingHandlerType.Contains(handlerType.BaseType))
DescriptorAspectsSet? aspects = HandlerInspector.GetAspects(handlerType); 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) StateKeeperAttributeBase? stateKeeperAttribute = HandlerInspector.GetStateKeeperAttribute(handlerType);
{ IFilter<Update>[] filters = HandlerInspector.GetFilterAttributes(handlerType, handlerAttribute.Type).ToArray();
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter);
}
if (aspects != null) UpdateType = handlerAttribute.Type;
{ Indexer = handlerAttribute.GetIndexer();
Aspects = aspects; FormReport = handlerAttribute.FormReport;
} Filters = new DescriptorFiltersSet(handlerAttribute, stateKeeperAttribute, filters);
} Aspects = HandlerInspector.GetAspects(handlerType);
DisplayString = HandlerInspector.GetDisplayName(handlerType);
} }
/// <summary> /// <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> /// </summary>
/// <param name="handlerType">The type of the handler.</param> /// <param name="handlerType">The type of the handler to describe</param>
/// <param name="serviceKey">The service key for the handler.</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) public HandlerDescriptor(Type handlerType, object serviceKey) : this(DescriptorType.Keyed, handlerType)
{ {
ServiceKey = serviceKey; ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey));
} }
/// <summary> /// <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> /// </summary>
/// <param name="type">The type of the descriptor.</param> /// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler.</param> /// <param name="handlerType">The type of the handler</param>
/// <param name="updateType">The update type handled by this 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="indexer">The indexer for handler concurrency and priority</param>
/// <param name="filters">The set of filters associated with this handler.</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) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters)
{ {
Type = type; Type = type;
@@ -213,15 +207,16 @@ namespace Telegrator.MadiatorCore.Descriptors
} }
/// <summary> /// <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> /// </summary>
/// <param name="type">The type of the descriptor.</param> /// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler.</param> /// <param name="handlerType">The type of the handler</param>
/// <param name="updateType">The update type handled by this 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="indexer">The indexer for handler concurrency and priority</param>
/// <param name="filters">The set of filters associated with this handler.</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="serviceKey">The service key for dependency injection</param>
/// <param name="singletonInstance">The singleton instance of the handler.</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) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters, object serviceKey, UpdateHandlerBase singletonInstance)
{ {
Type = type; Type = type;
@@ -229,19 +224,20 @@ namespace Telegrator.MadiatorCore.Descriptors
UpdateType = updateType; UpdateType = updateType;
Indexer = indexer; Indexer = indexer;
Filters = filters; Filters = filters;
ServiceKey = serviceKey; ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey));
SingletonInstance = singletonInstance; SingletonInstance = singletonInstance ?? throw new ArgumentNullException(nameof(singletonInstance));
} }
/// <summary> /// <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> /// </summary>
/// <param name="type">The type of the descriptor.</param> /// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler.</param> /// <param name="handlerType">The type of the handler</param>
/// <param name="updateType">The update type handled by this 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="indexer">The indexer for handler concurrency and priority</param>
/// <param name="filters">The set of filters associated with this handler.</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="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) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters, Func<UpdateHandlerBase> instanceFactory)
{ {
Type = type; Type = type;
@@ -249,19 +245,20 @@ namespace Telegrator.MadiatorCore.Descriptors
UpdateType = updateType; UpdateType = updateType;
Indexer = indexer; Indexer = indexer;
Filters = filters; Filters = filters;
InstanceFactory = instanceFactory; InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
} }
/// <summary> /// <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> /// </summary>
/// <param name="type">The type of the descriptor.</param> /// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler.</param> /// <param name="handlerType">The type of the handler</param>
/// <param name="updateType">The update type handled by this 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="indexer">The indexer for handler concurrency and priority</param>
/// <param name="filters">The set of filters associated with this handler.</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="serviceKey">The service key for dependency injection</param>
/// <param name="instanceFactory">The factory for creating handler instances.</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) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, DescriptorFiltersSet filters, object serviceKey, Func<UpdateHandlerBase> instanceFactory)
{ {
Type = type; Type = type;
@@ -269,243 +266,210 @@ namespace Telegrator.MadiatorCore.Descriptors
UpdateType = updateType; UpdateType = updateType;
Indexer = indexer; Indexer = indexer;
Filters = filters; Filters = filters;
ServiceKey = serviceKey; ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey));
InstanceFactory = instanceFactory; InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
} }
/// <summary> /// <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> /// </summary>
/// <param name="type">The type of the descriptor.</param> /// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler.</param> /// <param name="handlerType">The type of the handler</param>
/// <param name="pollingHandlerAttribute">The polling handler attribute.</param> /// <param name="pollingHandlerAttribute">The polling handler attribute containing configuration</param>
/// <param name="filters">The array of filters associated with this handler.</param> /// <param name="filters">Optional array of filters to apply</param>
/// <param name="stateKeepFilter">The state keeper filter.</param> /// <param name="stateKeepFilter">Optional state keeping filter</param>
public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter)
{ {
Type = type; Type = type;
HandlerType = handlerType; HandlerType = handlerType;
UpdateType = pollingHandlerAttribute.Type; UpdateType = pollingHandlerAttribute.Type;
Indexer = pollingHandlerAttribute.GetIndexer(); Indexer = pollingHandlerAttribute.GetIndexer();
FormReport = pollingHandlerAttribute.FormReport; Filters = new DescriptorFiltersSet(pollingHandlerAttribute, stateKeepFilter, filters);
if (filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter);
}
} }
/// <summary> /// <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> /// </summary>
/// <param name="type">The type of the descriptor.</param> /// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler.</param> /// <param name="handlerType">The type of the handler</param>
/// <param name="pollingHandlerAttribute">The polling handler attribute.</param> /// <param name="pollingHandlerAttribute">The polling handler attribute containing configuration</param>
/// <param name="filters">The array of filters associated with this handler.</param> /// <param name="filters">Optional array of filters to apply</param>
/// <param name="stateKeepFilter">The state keeper filter.</param> /// <param name="stateKeepFilter">Optional state keeping filter</param>
/// <param name="serviceKey">The service key for the handler.</param> /// <param name="serviceKey">The service key for dependency injection</param>
/// <param name="singletonInstance">The singleton instance of the handler.</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) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, object serviceKey, UpdateHandlerBase singletonInstance)
{ {
Type = type; Type = type;
HandlerType = handlerType; HandlerType = handlerType;
UpdateType = pollingHandlerAttribute.Type; UpdateType = pollingHandlerAttribute.Type;
Indexer = pollingHandlerAttribute.GetIndexer(); Indexer = pollingHandlerAttribute.GetIndexer();
FormReport = pollingHandlerAttribute.FormReport; Filters = new DescriptorFiltersSet(pollingHandlerAttribute, stateKeepFilter, filters);
ServiceKey = serviceKey; ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey));
SingletonInstance = singletonInstance; SingletonInstance = singletonInstance ?? throw new ArgumentNullException(nameof(singletonInstance));
if (filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter);
}
} }
/// <summary> /// <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> /// </summary>
/// <param name="type">The type of the descriptor.</param> /// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler.</param> /// <param name="handlerType">The type of the handler</param>
/// <param name="pollingHandlerAttribute">The polling handler attribute.</param> /// <param name="pollingHandlerAttribute">The polling handler attribute containing configuration</param>
/// <param name="filters">The array of filters associated with this handler.</param> /// <param name="filters">Optional array of filters to apply</param>
/// <param name="stateKeepFilter">The state keeper filter.</param> /// <param name="stateKeepFilter">Optional state keeping filter</param>
/// <param name="instanceFactory">The factory for creating handler instances.</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) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, Func<UpdateHandlerBase> instanceFactory)
{ {
Type = type; Type = type;
HandlerType = handlerType; HandlerType = handlerType;
UpdateType = pollingHandlerAttribute.Type; UpdateType = pollingHandlerAttribute.Type;
Indexer = pollingHandlerAttribute.GetIndexer(); Indexer = pollingHandlerAttribute.GetIndexer();
FormReport = pollingHandlerAttribute.FormReport; Filters = new DescriptorFiltersSet(pollingHandlerAttribute, stateKeepFilter, filters);
InstanceFactory = instanceFactory; InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
if (filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter);
}
} }
/// <summary> /// <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> /// </summary>
/// <param name="type">The type of the descriptor.</param> /// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler.</param> /// <param name="handlerType">The type of the handler</param>
/// <param name="pollingHandlerAttribute">The polling handler attribute.</param> /// <param name="pollingHandlerAttribute">The polling handler attribute containing configuration</param>
/// <param name="filters">The array of filters associated with this handler.</param> /// <param name="filters">Optional array of filters to apply</param>
/// <param name="stateKeepFilter">The state keeper filter.</param> /// <param name="stateKeepFilter">Optional state keeping filter</param>
/// <param name="serviceKey">The service key for the handler.</param> /// <param name="serviceKey">The service key for dependency injection</param>
/// <param name="instanceFactory">The factory for creating handler instances.</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) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateHandlerAttributeBase pollingHandlerAttribute, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, object serviceKey, Func<UpdateHandlerBase> instanceFactory)
{ {
Type = type; Type = type;
HandlerType = handlerType; HandlerType = handlerType;
UpdateType = pollingHandlerAttribute.Type; UpdateType = pollingHandlerAttribute.Type;
Indexer = pollingHandlerAttribute.GetIndexer(); Indexer = pollingHandlerAttribute.GetIndexer();
FormReport = pollingHandlerAttribute.FormReport; Filters = new DescriptorFiltersSet(pollingHandlerAttribute, stateKeepFilter, filters);
ServiceKey = serviceKey; ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey));
InstanceFactory = instanceFactory; InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
if (filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter);
}
} }
/// <summary> /// <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> /// </summary>
/// <param name="type">The type of the descriptor.</param> /// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler.</param> /// <param name="handlerType">The type of the handler</param>
/// <param name="updateType">The update type handled by this 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="indexer">The indexer for handler concurrency and priority</param>
/// <param name="validateFilter">The validation filter.</param> /// <param name="validateFilter">Optional validation filter</param>
/// <param name="filters">The array of filters associated with this handler.</param> /// <param name="filters">Optional array of filters to apply</param>
/// <param name="stateKeepFilter">The state keeper filter.</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) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, IFilter<Update>? validateFilter, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter)
{ {
Type = type; Type = type;
HandlerType = handlerType; HandlerType = handlerType;
UpdateType = updateType; UpdateType = updateType;
Indexer = indexer; Indexer = indexer;
Filters = new DescriptorFiltersSet(validateFilter, stateKeepFilter, filters);
if (validateFilter != null || filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter, validateFilter);
}
} }
/// <summary> /// <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> /// </summary>
/// <param name="type">The type of the descriptor.</param> /// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler.</param> /// <param name="handlerType">The type of the handler</param>
/// <param name="updateType">The update type handled by this 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="indexer">The indexer for handler concurrency and priority</param>
/// <param name="validateFilter">The validation filter.</param> /// <param name="validateFilter">Optional validation filter</param>
/// <param name="filters">The array of filters associated with this handler.</param> /// <param name="filters">Optional array of filters to apply</param>
/// <param name="stateKeepFilter">The state keeper filter.</param> /// <param name="stateKeepFilter">Optional state keeping filter</param>
/// <param name="serviceKey">The service key for the handler.</param> /// <param name="serviceKey">The service key for dependency injection</param>
/// <param name="singletonInstance">The singleton instance of the handler.</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) 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; Type = type;
HandlerType = handlerType; HandlerType = handlerType;
UpdateType = updateType; UpdateType = updateType;
Indexer = indexer; Indexer = indexer;
ServiceKey = serviceKey; Filters = new DescriptorFiltersSet(validateFilter, stateKeepFilter, filters);
SingletonInstance = singletonInstance; ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey));
SingletonInstance = singletonInstance ?? throw new ArgumentNullException(nameof(singletonInstance));
if (validateFilter != null || filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter, validateFilter);
}
} }
/// <summary> /// <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> /// </summary>
/// <param name="type">The type of the descriptor.</param> /// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler.</param> /// <param name="handlerType">The type of the handler</param>
/// <param name="updateType">The update type handled by this 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="indexer">The indexer for handler concurrency and priority</param>
/// <param name="validateFilter">The validation filter.</param> /// <param name="validateFilter">Optional validation filter</param>
/// <param name="filters">The array of filters associated with this handler.</param> /// <param name="filters">Optional array of filters to apply</param>
/// <param name="stateKeepFilter">The state keeper filter.</param> /// <param name="stateKeepFilter">Optional state keeping filter</param>
/// <param name="instanceFactory">The factory for creating handler instances.</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) public HandlerDescriptor(DescriptorType type, Type handlerType, UpdateType updateType, DescriptorIndexer indexer, IFilter<Update>? validateFilter, IFilter<Update>[]? filters, IFilter<Update>? stateKeepFilter, Func<UpdateHandlerBase> instanceFactory)
{ {
Type = type; Type = type;
HandlerType = handlerType; HandlerType = handlerType;
UpdateType = updateType; UpdateType = updateType;
Indexer = indexer; Indexer = indexer;
InstanceFactory = instanceFactory; Filters = new DescriptorFiltersSet(validateFilter, stateKeepFilter, filters);
InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
if (validateFilter != null || filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter, validateFilter);
}
} }
/// <summary> /// <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> /// </summary>
/// <param name="type">The type of the descriptor.</param> /// <param name="type">The type of the descriptor</param>
/// <param name="handlerType">The type of the handler.</param> /// <param name="handlerType">The type of the handler</param>
/// <param name="updateType">The update type handled by this 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="indexer">The indexer for handler concurrency and priority</param>
/// <param name="validateFilter">The validation filter.</param> /// <param name="validateFilter">Optional validation filter</param>
/// <param name="filters">The array of filters associated with this handler.</param> /// <param name="filters">Optional array of filters to apply</param>
/// <param name="stateKeepFilter">The state keeper filter.</param> /// <param name="stateKeepFilter">Optional state keeping filter</param>
/// <param name="serviceKey">The service key for the handler.</param> /// <param name="serviceKey">The service key for dependency injection</param>
/// <param name="instanceFactory">The factory for creating handler instances.</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) 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; Type = type;
HandlerType = handlerType; HandlerType = handlerType;
UpdateType = updateType; UpdateType = updateType;
Indexer = indexer; Indexer = indexer;
ServiceKey = serviceKey; Filters = new DescriptorFiltersSet(validateFilter, stateKeepFilter, filters);
InstanceFactory = instanceFactory; ServiceKey = serviceKey ?? throw new ArgumentNullException(nameof(serviceKey));
InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
if (validateFilter != null || filters != null || stateKeepFilter != null)
{
Filters = new DescriptorFiltersSet(filters ?? [], stateKeepFilter, validateFilter);
}
} }
/// <summary> /// <summary>
/// Sets the singleton instance for this handler descriptor. /// Sets singleton instance of this descriptor
/// Throws exception if instance already set
/// </summary> /// </summary>
/// <param name="instance">The singleton instance to set.</param> /// <param name="instance"></param>
/// <exception cref="Exception"></exception>
public void SetInstance(UpdateHandlerBase instance) public void SetInstance(UpdateHandlerBase instance)
{ {
if (Type != DescriptorType.Singleton) if (SingletonInstance != null)
throw new InvalidOperationException("Cannot set instance for non-singleton descriptor"); throw new Exception();
SingletonInstance = instance; SingletonInstance = instance;
} }
/// <summary> /// <summary>
/// Attempts to set the singleton instance for this handler descriptor. /// Tries to set singleton instance of this descriptor
/// </summary> /// </summary>
/// <param name="instance">The singleton instance to set.</param> /// <param name="instance"></param>
/// <returns>True if the instance was set successfully; otherwise, false.</returns> /// <returns></returns>
public bool TrySetInstance(UpdateHandlerBase instance) public bool TrySetInstance(UpdateHandlerBase instance)
{ {
if (Type != DescriptorType.Singleton) if (SingletonInstance != null)
return false; return false;
SingletonInstance = instance; SingletonInstance = instance;
return true; return true;
} }
/// <summary> /// <inheritdoc/>
/// Returns a string representation of this handler descriptor.
/// </summary>
/// <returns>A string representation of the handler descriptor.</returns>
public override string ToString() public override string ToString()
{ => DisplayString ?? HandlerType.Name;
return DisplayString ?? $"{Type} {HandlerType.Name}";
}
} }
} }