From 438bd4235906430b4e8722debb96473fb4e933bb Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 5 Sep 2023 10:56:05 +0800 Subject: [PATCH 1/2] Enable nullable annotations for Volo.Abp.Kafka --- framework/src/Volo.Abp.Kafka/Volo.Abp.Kafka.csproj | 2 ++ .../Volo.Abp.Kafka/Volo/Abp/Kafka/AbpKafkaOptions.cs | 6 +++--- .../Volo.Abp.Kafka/Volo/Abp/Kafka/ConsumerPool.cs | 2 +- .../Volo.Abp.Kafka/Volo/Abp/Kafka/IConsumerPool.cs | 2 +- .../Volo/Abp/Kafka/IKafkaMessageConsumerFactory.cs | 2 +- .../Volo.Abp.Kafka/Volo/Abp/Kafka/IProducerPool.cs | 2 +- .../Volo/Abp/Kafka/KafkaConnections.cs | 4 +++- .../Volo/Abp/Kafka/KafkaMessageConsumer.cs | 12 ++++++------ .../Volo/Abp/Kafka/KafkaMessageConsumerFactory.cs | 2 +- .../Volo.Abp.Kafka/Volo/Abp/Kafka/ProducerPool.cs | 2 +- 10 files changed, 20 insertions(+), 16 deletions(-) diff --git a/framework/src/Volo.Abp.Kafka/Volo.Abp.Kafka.csproj b/framework/src/Volo.Abp.Kafka/Volo.Abp.Kafka.csproj index f66761fc2a..e56bd38916 100644 --- a/framework/src/Volo.Abp.Kafka/Volo.Abp.Kafka.csproj +++ b/framework/src/Volo.Abp.Kafka/Volo.Abp.Kafka.csproj @@ -5,6 +5,8 @@ netstandard2.0;netstandard2.1;net7.0 + enable + Nullable diff --git a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/AbpKafkaOptions.cs b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/AbpKafkaOptions.cs index b48a952615..11b443f72b 100644 --- a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/AbpKafkaOptions.cs +++ b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/AbpKafkaOptions.cs @@ -8,11 +8,11 @@ public class AbpKafkaOptions { public KafkaConnections Connections { get; } - public Action ConfigureProducer { get; set; } + public Action? ConfigureProducer { get; set; } - public Action ConfigureConsumer { get; set; } + public Action? ConfigureConsumer { get; set; } - public Action ConfigureTopic { get; set; } + public Action? ConfigureTopic { get; set; } public AbpKafkaOptions() { diff --git a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/ConsumerPool.cs b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/ConsumerPool.cs index 7c73df0d51..48943c84c4 100644 --- a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/ConsumerPool.cs +++ b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/ConsumerPool.cs @@ -30,7 +30,7 @@ public class ConsumerPool : IConsumerPool, ISingletonDependency Logger = new NullLogger(); } - public virtual IConsumer Get(string groupId, string connectionName = null) + public virtual IConsumer Get(string groupId, string? connectionName = null) { connectionName ??= KafkaConnections.DefaultConnectionName; diff --git a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/IConsumerPool.cs b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/IConsumerPool.cs index 4666a0175f..a3f484ef56 100644 --- a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/IConsumerPool.cs +++ b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/IConsumerPool.cs @@ -5,5 +5,5 @@ namespace Volo.Abp.Kafka; public interface IConsumerPool : IDisposable { - IConsumer Get(string groupId, string connectionName = null); + IConsumer Get(string groupId, string? connectionName = null); } diff --git a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/IKafkaMessageConsumerFactory.cs b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/IKafkaMessageConsumerFactory.cs index e21c8c9fd2..985e20625f 100644 --- a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/IKafkaMessageConsumerFactory.cs +++ b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/IKafkaMessageConsumerFactory.cs @@ -14,5 +14,5 @@ public interface IKafkaMessageConsumerFactory IKafkaMessageConsumer Create( string topicName, string groupId, - string connectionName = null); + string? connectionName = null); } diff --git a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/IProducerPool.cs b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/IProducerPool.cs index 8930184016..378075b2ec 100644 --- a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/IProducerPool.cs +++ b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/IProducerPool.cs @@ -5,5 +5,5 @@ namespace Volo.Abp.Kafka; public interface IProducerPool : IDisposable { - IProducer Get(string connectionName = null); + IProducer Get(string? connectionName = null); } diff --git a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/KafkaConnections.cs b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/KafkaConnections.cs index 3d9f2fe950..e66e074ad6 100644 --- a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/KafkaConnections.cs +++ b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/KafkaConnections.cs @@ -21,8 +21,10 @@ public class KafkaConnections : Dictionary Default = new ClientConfig(); } - public ClientConfig GetOrDefault(string connectionName) + public ClientConfig GetOrDefault(string? connectionName) { + connectionName ??= DefaultConnectionName; + if (TryGetValue(connectionName, out var connectionFactory)) { return connectionFactory; diff --git a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/KafkaMessageConsumer.cs b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/KafkaMessageConsumer.cs index 704c15845f..5a2ba38189 100644 --- a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/KafkaMessageConsumer.cs +++ b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/KafkaMessageConsumer.cs @@ -31,13 +31,13 @@ public class KafkaMessageConsumer : IKafkaMessageConsumer, ITransientDependency, protected ConcurrentBag, Task>> Callbacks { get; } - protected IConsumer Consumer { get; private set; } + protected IConsumer? Consumer { get; private set; } - protected string ConnectionName { get; private set; } + protected string? ConnectionName { get; private set; } - protected string GroupId { get; private set; } + protected string GroupId { get; private set; } = default!; - protected string TopicName { get; private set; } + protected string TopicName { get; private set; } = default!; public KafkaMessageConsumer( IConsumerPool consumerPool, @@ -63,7 +63,7 @@ public class KafkaMessageConsumer : IKafkaMessageConsumer, ITransientDependency, public virtual void Initialize( [NotNull] string topicName, [NotNull] string groupId, - string connectionName = null) + string? connectionName = null) { Check.NotNull(topicName, nameof(topicName)); Check.NotNull(groupId, nameof(groupId)); @@ -160,7 +160,7 @@ public class KafkaMessageConsumer : IKafkaMessageConsumer, ITransientDependency, } finally { - Consumer.Commit(consumeResult); + Consumer?.Commit(consumeResult); } } diff --git a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/KafkaMessageConsumerFactory.cs b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/KafkaMessageConsumerFactory.cs index dfc5912d55..fe46b5fe38 100644 --- a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/KafkaMessageConsumerFactory.cs +++ b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/KafkaMessageConsumerFactory.cs @@ -16,7 +16,7 @@ public class KafkaMessageConsumerFactory : IKafkaMessageConsumerFactory, ISingle public IKafkaMessageConsumer Create( string topicName, string groupId, - string connectionName = null) + string? connectionName = null) { var consumer = ServiceScope.ServiceProvider.GetRequiredService(); consumer.Initialize(topicName, groupId, connectionName); diff --git a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/ProducerPool.cs b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/ProducerPool.cs index ac2edf31a7..23b9b71a57 100644 --- a/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/ProducerPool.cs +++ b/framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/ProducerPool.cs @@ -32,7 +32,7 @@ public class ProducerPool : IProducerPool, ISingletonDependency Logger = new NullLogger(); } - public virtual IProducer Get(string connectionName = null) + public virtual IProducer Get(string? connectionName = null) { connectionName ??= KafkaConnections.DefaultConnectionName; From 106d5105613948c36e3bc0187c91d97e7ee1296c Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 5 Sep 2023 10:56:22 +0800 Subject: [PATCH 2/2] Enable nullable annotations for Volo.Abp.EventBus.* --- .../AzureServiceBusMessageConsumerFactory.cs | 2 +- .../Volo/Abp/AzureServiceBus/ConnectionPool.cs | 4 ++-- .../IAzureServiceBusMessageConsumerFactory.cs | 2 +- .../Abp/AzureServiceBus/IConnectionPool.cs | 4 ++-- .../Volo/Abp/AzureServiceBus/IPublisherPool.cs | 2 +- .../Volo/Abp/AzureServiceBus/PublisherPool.cs | 2 +- .../Volo.Abp.EventBus.Abstractions.csproj | 2 ++ .../Distributed/DistributedEventReceived.cs | 4 ++-- .../Distributed/DistributedEventSent.cs | 4 ++-- .../Abp/EventBus/Distributed/InboxConfig.cs | 8 ++++---- .../EventBus/Distributed/IncomingEventInfo.cs | 8 ++++---- .../Abp/EventBus/Distributed/OutboxConfig.cs | 6 +++--- .../EventBus/Distributed/OutgoingEventInfo.cs | 6 +++--- .../Volo/Abp/EventBus/EventNameAttribute.cs | 12 ++++++------ .../Abp/EventBus/GenericEventNameAttribute.cs | 4 ++-- .../Volo.Abp.EventBus.Azure.csproj | 2 ++ .../EventBus/Azure/AbpAzureEventBusOptions.cs | 6 +++--- .../EventBus/Azure/AzureDistributedEventBus.cs | 4 ++-- .../Volo.Abp.EventBus.Dapr.csproj | 2 ++ .../Volo/Abp/EventBus/Dapr/AbpDaprEventData.cs | 4 ++-- .../EventBus/Dapr/DaprDistributedEventBus.cs | 10 +++++----- .../Volo.Abp.EventBus.Kafka.csproj | 2 ++ .../EventBus/Kafka/AbpKafkaEventBusOptions.cs | 6 +++--- .../EventBus/Kafka/KafkaDistributedEventBus.cs | 2 +- .../Abp/EventBus/Kafka/MessageExtensions.cs | 8 ++++---- .../Volo.Abp.EventBus.RabbitMQ.csproj | 2 ++ .../RabbitMq/AbpRabbitMqEventBusOptions.cs | 10 +++++----- .../RabbitMq/RabbitMqDistributedEventBus.cs | 18 +++++++++--------- .../Volo.Abp.EventBus.Rebus.csproj | 2 ++ .../EventBus/Rebus/AbpRebusEventBusOptions.cs | 4 ++-- .../EventBus/Rebus/RebusDistributedEventBus.cs | 8 ++++---- .../RebusDistributedEventHandlerAdapter.cs | 2 +- .../Volo.Abp.EventBus/Volo.Abp.EventBus.csproj | 2 ++ .../Distributed/DistributedEventBusBase.cs | 14 +++++++------- .../Abp/EventBus/Distributed/InboxProcessor.cs | 6 +++--- .../Abp/EventBus/Distributed/OutboxSender.cs | 6 +++--- .../Volo/Abp/EventBus/EventBusBase.cs | 8 ++++---- .../Abp/EventBus/EventHandlerDisposeWrapper.cs | 4 ++-- .../Volo/Abp/EventBus/EventHandlerInvoker.cs | 4 ++-- .../EventBus/EventHandlerInvokerCacheItem.cs | 4 ++-- .../Volo/Abp/EventBus/Local/LocalEventBus.cs | 6 +++--- .../EventBus/TransientEventHandlerFactory.cs | 2 +- 42 files changed, 116 insertions(+), 102 deletions(-) diff --git a/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/AzureServiceBusMessageConsumerFactory.cs b/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/AzureServiceBusMessageConsumerFactory.cs index 04c7b48c6a..cf92ed7b73 100644 --- a/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/AzureServiceBusMessageConsumerFactory.cs +++ b/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/AzureServiceBusMessageConsumerFactory.cs @@ -14,7 +14,7 @@ public class AzureServiceBusMessageConsumerFactory : IAzureServiceBusMessageCons ServiceScope = serviceScopeFactory.CreateScope(); } - public IAzureServiceBusMessageConsumer CreateMessageConsumer(string topicName, string subscriptionName, string connectionName) + public IAzureServiceBusMessageConsumer CreateMessageConsumer(string topicName, string subscriptionName, string? connectionName) { var processor = ServiceScope.ServiceProvider.GetRequiredService(); processor.Initialize(topicName, subscriptionName, connectionName); diff --git a/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/ConnectionPool.cs b/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/ConnectionPool.cs index d616e1264f..df830cde7a 100644 --- a/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/ConnectionPool.cs +++ b/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/ConnectionPool.cs @@ -28,7 +28,7 @@ public class ConnectionPool : IConnectionPool, ISingletonDependency Logger = new NullLogger(); } - public ServiceBusClient GetClient(string connectionName) + public ServiceBusClient GetClient(string? connectionName) { connectionName ??= AzureServiceBusConnections.DefaultConnectionName; return _clients.GetOrAdd( @@ -40,7 +40,7 @@ public class ConnectionPool : IConnectionPool, ISingletonDependency ).Value; } - public ServiceBusAdministrationClient GetAdministrationClient(string connectionName) + public ServiceBusAdministrationClient GetAdministrationClient(string? connectionName) { connectionName ??= AzureServiceBusConnections.DefaultConnectionName; return _adminClients.GetOrAdd( diff --git a/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/IAzureServiceBusMessageConsumerFactory.cs b/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/IAzureServiceBusMessageConsumerFactory.cs index bd770e2204..4d93bcf5c3 100644 --- a/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/IAzureServiceBusMessageConsumerFactory.cs +++ b/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/IAzureServiceBusMessageConsumerFactory.cs @@ -16,5 +16,5 @@ public interface IAzureServiceBusMessageConsumerFactory IAzureServiceBusMessageConsumer CreateMessageConsumer( string topicName, string subscriptionName, - string connectionName); + string? connectionName); } diff --git a/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/IConnectionPool.cs b/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/IConnectionPool.cs index a4cdfbc122..825c981a00 100644 --- a/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/IConnectionPool.cs +++ b/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/IConnectionPool.cs @@ -6,7 +6,7 @@ namespace Volo.Abp.AzureServiceBus; public interface IConnectionPool : IAsyncDisposable { - ServiceBusClient GetClient(string connectionName); + ServiceBusClient GetClient(string? connectionName); - ServiceBusAdministrationClient GetAdministrationClient(string connectionName); + ServiceBusAdministrationClient GetAdministrationClient(string? connectionName); } diff --git a/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/IPublisherPool.cs b/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/IPublisherPool.cs index 4940d250dd..bb0bf8e827 100644 --- a/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/IPublisherPool.cs +++ b/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/IPublisherPool.cs @@ -6,5 +6,5 @@ namespace Volo.Abp.AzureServiceBus; public interface IPublisherPool : IAsyncDisposable { - Task GetAsync(string topicName, string connectionName); + Task GetAsync(string topicName, string? connectionName); } diff --git a/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/PublisherPool.cs b/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/PublisherPool.cs index 45b025cc59..a10c63868d 100644 --- a/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/PublisherPool.cs +++ b/framework/src/Volo.Abp.AzureServiceBus/Volo/Abp/AzureServiceBus/PublisherPool.cs @@ -24,7 +24,7 @@ public class PublisherPool : IPublisherPool, ISingletonDependency Logger = new NullLogger(); } - public async Task GetAsync(string topicName, string connectionName) + public async Task GetAsync(string topicName, string? connectionName) { var admin = _connectionPool.GetAdministrationClient(connectionName); await admin.SetupTopicAsync(topicName); diff --git a/framework/src/Volo.Abp.EventBus.Abstractions/Volo.Abp.EventBus.Abstractions.csproj b/framework/src/Volo.Abp.EventBus.Abstractions/Volo.Abp.EventBus.Abstractions.csproj index b61d8315c1..d9a78b320b 100644 --- a/framework/src/Volo.Abp.EventBus.Abstractions/Volo.Abp.EventBus.Abstractions.csproj +++ b/framework/src/Volo.Abp.EventBus.Abstractions/Volo.Abp.EventBus.Abstractions.csproj @@ -5,6 +5,8 @@ netstandard2.0;netstandard2.1;net7.0 + enable + Nullable diff --git a/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/DistributedEventReceived.cs b/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/DistributedEventReceived.cs index 42036d85ce..86d6009594 100644 --- a/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/DistributedEventReceived.cs +++ b/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/DistributedEventReceived.cs @@ -4,7 +4,7 @@ public class DistributedEventReceived { public DistributedEventSource Source { get; set; } - public string EventName { get; set; } + public string EventName { get; set; } = default!; - public object EventData { get; set; } + public object EventData { get; set; } = default!; } diff --git a/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/DistributedEventSent.cs b/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/DistributedEventSent.cs index 990068e0cc..d94f927e35 100644 --- a/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/DistributedEventSent.cs +++ b/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/DistributedEventSent.cs @@ -4,7 +4,7 @@ public class DistributedEventSent { public DistributedEventSource Source { get; set; } - public string EventName { get; set; } + public string EventName { get; set; } = default!; - public object EventData { get; set; } + public object EventData { get; set; } = default!; } diff --git a/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/InboxConfig.cs b/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/InboxConfig.cs index 94e0e55be9..35af3f2bc9 100644 --- a/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/InboxConfig.cs +++ b/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/InboxConfig.cs @@ -13,13 +13,13 @@ public class InboxConfig get => _databaseName; set => _databaseName = Check.NotNullOrWhiteSpace(value, nameof(DatabaseName)); } - [NotNull] private string _databaseName; + [NotNull] private string _databaseName = default!; - public Type ImplementationType { get; set; } + public Type ImplementationType { get; set; } = default!; - public Func EventSelector { get; set; } + public Func? EventSelector { get; set; } - public Func HandlerSelector { get; set; } + public Func? HandlerSelector { get; set; } /// /// Used to enable/disable processing incoming events. diff --git a/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/IncomingEventInfo.cs b/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/IncomingEventInfo.cs index 372e4e3d77..ffd135845a 100644 --- a/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/IncomingEventInfo.cs +++ b/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/IncomingEventInfo.cs @@ -12,11 +12,11 @@ public class IncomingEventInfo : IHasExtraProperties public Guid Id { get; } - public string MessageId { get; } + public string MessageId { get; } = default!; - public string EventName { get; } + public string EventName { get; } = default!; - public byte[] EventData { get; } + public byte[] EventData { get; } = default!; public DateTime CreationTime { get; } @@ -47,7 +47,7 @@ public class IncomingEventInfo : IHasExtraProperties ExtraProperties[EventBusConsts.CorrelationIdHeaderName] = correlationId; } - public string GetCorrelationId() + public string? GetCorrelationId() { return ExtraProperties.GetOrDefault(EventBusConsts.CorrelationIdHeaderName)?.ToString(); } diff --git a/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/OutboxConfig.cs b/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/OutboxConfig.cs index 0b327c0e3b..6e44b9c470 100644 --- a/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/OutboxConfig.cs +++ b/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/OutboxConfig.cs @@ -13,11 +13,11 @@ public class OutboxConfig get => _databaseName; set => _databaseName = Check.NotNullOrWhiteSpace(value, nameof(DatabaseName)); } - [NotNull] private string _databaseName; + [NotNull] private string _databaseName = default!; - public Type ImplementationType { get; set; } + public Type ImplementationType { get; set; } = default!; - public Func Selector { get; set; } + public Func? Selector { get; set; } /// /// Used to enable/disable sending events from outbox to the message broker. diff --git a/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/OutgoingEventInfo.cs b/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/OutgoingEventInfo.cs index 299935741e..43e9c42bf8 100644 --- a/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/OutgoingEventInfo.cs +++ b/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/Distributed/OutgoingEventInfo.cs @@ -12,9 +12,9 @@ public class OutgoingEventInfo : IHasExtraProperties public Guid Id { get; } - public string EventName { get; } + public string EventName { get; } = default!; - public byte[] EventData { get; } + public byte[] EventData { get; } = default!; public DateTime CreationTime { get; } @@ -43,7 +43,7 @@ public class OutgoingEventInfo : IHasExtraProperties ExtraProperties[EventBusConsts.CorrelationIdHeaderName] = correlationId; } - public string GetCorrelationId() + public string? GetCorrelationId() { return ExtraProperties.GetOrDefault(EventBusConsts.CorrelationIdHeaderName)?.ToString(); } diff --git a/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/EventNameAttribute.cs b/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/EventNameAttribute.cs index 1f0b19dd3c..2ae85bd428 100644 --- a/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/EventNameAttribute.cs +++ b/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/EventNameAttribute.cs @@ -23,12 +23,12 @@ public class EventNameAttribute : Attribute, IEventNameProvider { Check.NotNull(eventType, nameof(eventType)); - return eventType - .GetCustomAttributes(true) - .OfType() - .FirstOrDefault() - ?.GetName(eventType) - ?? eventType.FullName; + return (eventType + .GetCustomAttributes(true) + .OfType() + .FirstOrDefault() + ?.GetName(eventType) + ?? eventType.FullName)!; } public string GetName(Type eventType) diff --git a/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/GenericEventNameAttribute.cs b/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/GenericEventNameAttribute.cs index 70493104c1..99c089be85 100644 --- a/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/GenericEventNameAttribute.cs +++ b/framework/src/Volo.Abp.EventBus.Abstractions/Volo/Abp/EventBus/GenericEventNameAttribute.cs @@ -5,9 +5,9 @@ namespace Volo.Abp.EventBus; [AttributeUsage(AttributeTargets.Class)] public class GenericEventNameAttribute : Attribute, IEventNameProvider { - public string Prefix { get; set; } + public string? Prefix { get; set; } - public string Postfix { get; set; } + public string? Postfix { get; set; } public virtual string GetName(Type eventType) { diff --git a/framework/src/Volo.Abp.EventBus.Azure/Volo.Abp.EventBus.Azure.csproj b/framework/src/Volo.Abp.EventBus.Azure/Volo.Abp.EventBus.Azure.csproj index 7cbaa944da..d467bd3796 100644 --- a/framework/src/Volo.Abp.EventBus.Azure/Volo.Abp.EventBus.Azure.csproj +++ b/framework/src/Volo.Abp.EventBus.Azure/Volo.Abp.EventBus.Azure.csproj @@ -5,6 +5,8 @@ netstandard2.0;netstandard2.1;net7.0 + enable + Nullable Volo.Abp.EventBus.Azure Volo.Abp.EventBus.Azure $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; diff --git a/framework/src/Volo.Abp.EventBus.Azure/Volo/Abp/EventBus/Azure/AbpAzureEventBusOptions.cs b/framework/src/Volo.Abp.EventBus.Azure/Volo/Abp/EventBus/Azure/AbpAzureEventBusOptions.cs index 57fa4b7f48..a6c5aabf42 100644 --- a/framework/src/Volo.Abp.EventBus.Azure/Volo/Abp/EventBus/Azure/AbpAzureEventBusOptions.cs +++ b/framework/src/Volo.Abp.EventBus.Azure/Volo/Abp/EventBus/Azure/AbpAzureEventBusOptions.cs @@ -2,11 +2,11 @@ namespace Volo.Abp.EventBus.Azure; public class AbpAzureEventBusOptions { - public string ConnectionName { get; set; } + public string? ConnectionName { get; set; } - public string SubscriberName { get; set; } + public string SubscriberName { get; set; } = default!; - public string TopicName { get; set; } + public string TopicName { get; set; } = default!; public bool IsServiceBusDisabled { get; set; } } diff --git a/framework/src/Volo.Abp.EventBus.Azure/Volo/Abp/EventBus/Azure/AzureDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.Azure/Volo/Abp/EventBus/Azure/AzureDistributedEventBus.cs index d7ca68bee6..8e45a8887f 100644 --- a/framework/src/Volo.Abp.EventBus.Azure/Volo/Abp/EventBus/Azure/AzureDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus.Azure/Volo/Abp/EventBus/Azure/AzureDistributedEventBus.cs @@ -30,7 +30,7 @@ public class AzureDistributedEventBus : DistributedEventBusBase, ISingletonDepen protected IAzureServiceBusSerializer Serializer { get; } protected ConcurrentDictionary> HandlerFactories { get; } protected ConcurrentDictionary EventTypes { get; } - protected IAzureServiceBusMessageConsumer Consumer { get; private set; } + protected IAzureServiceBusMessageConsumer Consumer { get; private set; } = default!; public AzureDistributedEventBus( IServiceScopeFactory serviceScopeFactory, @@ -268,7 +268,7 @@ public class AzureDistributedEventBus : DistributedEventBusBase, ISingletonDepen protected virtual async Task PublishAsync( string eventName, byte[] body, - [CanBeNull] string correlationId, + string? correlationId, Guid? eventId) { var message = new ServiceBusMessage(body) diff --git a/framework/src/Volo.Abp.EventBus.Dapr/Volo.Abp.EventBus.Dapr.csproj b/framework/src/Volo.Abp.EventBus.Dapr/Volo.Abp.EventBus.Dapr.csproj index 61f398fecf..47d0f09f64 100644 --- a/framework/src/Volo.Abp.EventBus.Dapr/Volo.Abp.EventBus.Dapr.csproj +++ b/framework/src/Volo.Abp.EventBus.Dapr/Volo.Abp.EventBus.Dapr.csproj @@ -5,6 +5,8 @@ net7.0 + enable + Nullable diff --git a/framework/src/Volo.Abp.EventBus.Dapr/Volo/Abp/EventBus/Dapr/AbpDaprEventData.cs b/framework/src/Volo.Abp.EventBus.Dapr/Volo/Abp/EventBus/Dapr/AbpDaprEventData.cs index ee08586b8d..b4dfee64cd 100644 --- a/framework/src/Volo.Abp.EventBus.Dapr/Volo/Abp/EventBus/Dapr/AbpDaprEventData.cs +++ b/framework/src/Volo.Abp.EventBus.Dapr/Volo/Abp/EventBus/Dapr/AbpDaprEventData.cs @@ -10,9 +10,9 @@ public class AbpDaprEventData public string JsonData { get; set; } - public string CorrelationId { get; set; } + public string? CorrelationId { get; set; } - public AbpDaprEventData(string pubSubName, string topic, string messageId, string jsonData, string correlationId) + public AbpDaprEventData(string pubSubName, string topic, string messageId, string jsonData, string? correlationId) { PubSubName = pubSubName; Topic = topic; diff --git a/framework/src/Volo.Abp.EventBus.Dapr/Volo/Abp/EventBus/Dapr/DaprDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.Dapr/Volo/Abp/EventBus/Dapr/DaprDistributedEventBus.cs index 4912a58388..f4c3e6242f 100644 --- a/framework/src/Volo.Abp.EventBus.Dapr/Volo/Abp/EventBus/Dapr/DaprDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus.Dapr/Volo/Abp/EventBus/Dapr/DaprDistributedEventBus.cs @@ -114,7 +114,7 @@ public class DaprDistributedEventBus : DistributedEventBusBase, ISingletonDepend factories.RemoveAll( factory => factory is SingleInstanceHandlerFactory && - (factory as SingleInstanceHandlerFactory).HandlerInstance == handler + (factory as SingleInstanceHandlerFactory)!.HandlerInstance == handler ); }); } @@ -186,7 +186,7 @@ public class DaprDistributedEventBus : DistributedEventBusBase, ISingletonDepend } } - public virtual async Task TriggerHandlersAsync(Type eventType, object eventData, string messageId = null, string correlationId = null) + public virtual async Task TriggerHandlersAsync(Type eventType, object eventData, string? messageId = null, string? correlationId = null) { if (await AddToInboxAsync(messageId, EventNameAttribute.GetNameOrDefault(eventType), eventType, eventData, correlationId)) { @@ -245,15 +245,15 @@ public class DaprDistributedEventBus : DistributedEventBusBase, ISingletonDepend public Type GetEventType(string eventName) { - return EventTypes.GetOrDefault(eventName); + return EventTypes.GetOrDefault(eventName)!; } - protected virtual async Task PublishToDaprAsync(Type eventType, object eventData, Guid? messageId = null, string correlationId = null) + protected virtual async Task PublishToDaprAsync(Type eventType, object eventData, Guid? messageId = null, string? correlationId = null) { await PublishToDaprAsync(EventNameAttribute.GetNameOrDefault(eventType), eventData, messageId, correlationId); } - protected virtual async Task PublishToDaprAsync(string eventName, object eventData, Guid? messageId = null, string correlationId = null) + protected virtual async Task PublishToDaprAsync(string eventName, object eventData, Guid? messageId = null, string? correlationId = null) { var client = DaprClientFactory.Create(); var data = new AbpDaprEventData(DaprEventBusOptions.PubSubName, eventName, (messageId ?? GuidGenerator.Create()).ToString("N"), Serializer.SerializeToString(eventData), correlationId); diff --git a/framework/src/Volo.Abp.EventBus.Kafka/Volo.Abp.EventBus.Kafka.csproj b/framework/src/Volo.Abp.EventBus.Kafka/Volo.Abp.EventBus.Kafka.csproj index 9a240aa49a..4d2ff65bd4 100644 --- a/framework/src/Volo.Abp.EventBus.Kafka/Volo.Abp.EventBus.Kafka.csproj +++ b/framework/src/Volo.Abp.EventBus.Kafka/Volo.Abp.EventBus.Kafka.csproj @@ -5,6 +5,8 @@ netstandard2.0;netstandard2.1;net7.0 + enable + Nullable diff --git a/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/AbpKafkaEventBusOptions.cs b/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/AbpKafkaEventBusOptions.cs index eb5f898e68..17dc9e3796 100644 --- a/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/AbpKafkaEventBusOptions.cs +++ b/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/AbpKafkaEventBusOptions.cs @@ -3,9 +3,9 @@ public class AbpKafkaEventBusOptions { - public string ConnectionName { get; set; } + public string? ConnectionName { get; set; } - public string TopicName { get; set; } + public string TopicName { get; set; } = default!; - public string GroupId { get; set; } + public string GroupId { get; set; } = default!; } diff --git a/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaDistributedEventBus.cs index b49ffc07a9..a777ff7da2 100644 --- a/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaDistributedEventBus.cs @@ -29,7 +29,7 @@ public class KafkaDistributedEventBus : DistributedEventBusBase, ISingletonDepen protected IProducerPool ProducerPool { get; } protected ConcurrentDictionary> HandlerFactories { get; } protected ConcurrentDictionary EventTypes { get; } - protected IKafkaMessageConsumer Consumer { get; private set; } + protected IKafkaMessageConsumer Consumer { get; private set; } = default!; public KafkaDistributedEventBus( IServiceScopeFactory serviceScopeFactory, diff --git a/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/MessageExtensions.cs b/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/MessageExtensions.cs index 569e56a1dc..cb487ed00f 100644 --- a/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/MessageExtensions.cs +++ b/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/MessageExtensions.cs @@ -4,9 +4,9 @@ namespace Volo.Abp.EventBus.Kafka; public static class MessageExtensions { - public static string GetMessageId(this Message message) + public static string? GetMessageId(this Message message) { - string messageId = null; + string? messageId = null; if (message.Headers.TryGetLastBytes("messageId", out var messageIdBytes)) { @@ -16,9 +16,9 @@ public static class MessageExtensions return messageId; } - public static string GetCorrelationId(this Message message) + public static string? GetCorrelationId(this Message message) { - string correlationId = null; + string? correlationId = null; if (message.Headers.TryGetLastBytes(EventBusConsts.CorrelationIdHeaderName, out var correlationIdBytes)) { diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo.Abp.EventBus.RabbitMQ.csproj b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo.Abp.EventBus.RabbitMQ.csproj index 73c4d4a69a..b9d46a8a99 100644 --- a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo.Abp.EventBus.RabbitMQ.csproj +++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo.Abp.EventBus.RabbitMQ.csproj @@ -5,6 +5,8 @@ netstandard2.0;netstandard2.1;net7.0 + enable + Nullable Volo.Abp.EventBus.RabbitMQ Volo.Abp.EventBus.RabbitMQ $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpRabbitMqEventBusOptions.cs b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpRabbitMqEventBusOptions.cs index bac9bdf0c9..a017d53d5d 100644 --- a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpRabbitMqEventBusOptions.cs +++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpRabbitMqEventBusOptions.cs @@ -6,13 +6,13 @@ public class AbpRabbitMqEventBusOptions { public const string DefaultExchangeType = RabbitMqConsts.ExchangeTypes.Direct; - public string ConnectionName { get; set; } + public string? ConnectionName { get; set; } - public string ClientName { get; set; } + public string ClientName { get; set; } = default!; - public string ExchangeName { get; set; } + public string ExchangeName { get; set; } = default!; - public string ExchangeType { get; set; } + public string? ExchangeType { get; set; } public ushort? PrefetchCount { get; set; } @@ -20,6 +20,6 @@ public class AbpRabbitMqEventBusOptions { return string.IsNullOrEmpty(ExchangeType) ? DefaultExchangeType - : ExchangeType; + : ExchangeType!; } } diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs index e484fa792b..2c0bb7aab5 100644 --- a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs @@ -35,7 +35,7 @@ public class RabbitMqDistributedEventBus : DistributedEventBusBase, ISingletonDe protected ConcurrentDictionary> HandlerFactories { get; } protected ConcurrentDictionary EventTypes { get; } protected IRabbitMqMessageConsumerFactory MessageConsumerFactory { get; } - protected IRabbitMqMessageConsumer Consumer { get; private set; } + protected IRabbitMqMessageConsumer Consumer { get; private set; } = default!; private bool _exchangeCreated; @@ -175,7 +175,7 @@ public class RabbitMqDistributedEventBus : DistributedEventBusBase, ISingletonDe factories.RemoveAll( factory => factory is SingleInstanceHandlerFactory && - (factory as SingleInstanceHandlerFactory).HandlerInstance == handler + (factory as SingleInstanceHandlerFactory)!.HandlerInstance == handler ); }); } @@ -282,9 +282,9 @@ public class RabbitMqDistributedEventBus : DistributedEventBusBase, ISingletonDe public virtual Task PublishAsync( Type eventType, object eventData, - Dictionary headersArguments = null, + Dictionary? headersArguments = null, Guid? eventId = null, - [CanBeNull] string correlationId = null) + string? correlationId = null) { var eventName = EventNameAttribute.GetNameOrDefault(eventType); var body = Serializer.Serialize(eventData); @@ -295,9 +295,9 @@ public class RabbitMqDistributedEventBus : DistributedEventBusBase, ISingletonDe protected virtual Task PublishAsync( string eventName, byte[] body, - Dictionary headersArguments = null, + Dictionary? headersArguments = null, Guid? eventId = null, - [CanBeNull] string correlationId = null) + string? correlationId = null) { using (var channel = ConnectionPool.Get(AbpRabbitMqEventBusOptions.ConnectionName).CreateModel()) { @@ -309,9 +309,9 @@ public class RabbitMqDistributedEventBus : DistributedEventBusBase, ISingletonDe IModel channel, string eventName, byte[] body, - Dictionary headersArguments = null, + Dictionary? headersArguments = null, Guid? eventId = null, - [CanBeNull] string correlationId = null) + string? correlationId = null) { EnsureExchangeExists(channel); @@ -366,7 +366,7 @@ public class RabbitMqDistributedEventBus : DistributedEventBusBase, ISingletonDe _exchangeCreated = true; } - private void SetEventMessageHeaders(IBasicProperties properties, Dictionary headersArguments) + private void SetEventMessageHeaders(IBasicProperties properties, Dictionary? headersArguments) { if (headersArguments == null) { diff --git a/framework/src/Volo.Abp.EventBus.Rebus/Volo.Abp.EventBus.Rebus.csproj b/framework/src/Volo.Abp.EventBus.Rebus/Volo.Abp.EventBus.Rebus.csproj index 9800674fab..f8c668dd8e 100644 --- a/framework/src/Volo.Abp.EventBus.Rebus/Volo.Abp.EventBus.Rebus.csproj +++ b/framework/src/Volo.Abp.EventBus.Rebus/Volo.Abp.EventBus.Rebus.csproj @@ -5,6 +5,8 @@ netstandard2.0;netstandard2.1;net7.0 + enable + Nullable Volo.Abp.EventBus.Rebus Volo.Abp.EventBus.Rebus $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; diff --git a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpRebusEventBusOptions.cs b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpRebusEventBusOptions.cs index 4c39b9bf1d..d128621396 100644 --- a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpRebusEventBusOptions.cs +++ b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpRebusEventBusOptions.cs @@ -11,7 +11,7 @@ namespace Volo.Abp.EventBus.Rebus; public class AbpRebusEventBusOptions { [NotNull] - public string InputQueueName { get; set; } + public string InputQueueName { get; set; } = default!; [NotNull] public Action Configurer { @@ -20,7 +20,7 @@ public class AbpRebusEventBusOptions } private Action _configurer; - public Func Publish { get; set; } + public Func? Publish { get; set; } public AbpRebusEventBusOptions() { diff --git a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusDistributedEventBus.cs index 560b13ba14..4b4dd3eef7 100644 --- a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusDistributedEventBus.cs @@ -165,7 +165,7 @@ public class RebusDistributedEventBus : DistributedEventBusBase, ISingletonDepen var headers = new Dictionary(); if (CorrelationIdProvider.Get() != null) { - headers.Add(EventBusConsts.CorrelationIdHeaderName, CorrelationIdProvider.Get()); + headers.Add(EventBusConsts.CorrelationIdHeaderName, CorrelationIdProvider.Get()!); } await PublishAsync(eventType, eventData, headersArguments: headers); } @@ -174,7 +174,7 @@ public class RebusDistributedEventBus : DistributedEventBusBase, ISingletonDepen Type eventType, object eventData, Guid? eventId = null, - Dictionary headersArguments = null) + Dictionary? headersArguments = null) { if (AbpRebusEventBusOptions.Publish != null) { @@ -250,7 +250,7 @@ public class RebusDistributedEventBus : DistributedEventBusBase, ISingletonDepen OutgoingEventInfo outgoingEvent, OutboxConfig outboxConfig) { - var eventType = EventTypes.GetOrDefault(outgoingEvent.EventName); + var eventType = EventTypes.GetOrDefault(outgoingEvent.EventName)!; var eventData = Serializer.Deserialize(outgoingEvent.EventData, eventType); using (CorrelationIdProvider.Change(outgoingEvent.GetCorrelationId())) @@ -265,7 +265,7 @@ public class RebusDistributedEventBus : DistributedEventBusBase, ISingletonDepen var headers = new Dictionary(); if (outgoingEvent.GetCorrelationId() != null) { - headers.Add(EventBusConsts.CorrelationIdHeaderName, outgoingEvent.GetCorrelationId()); + headers.Add(EventBusConsts.CorrelationIdHeaderName, outgoingEvent.GetCorrelationId()!); } await PublishAsync(eventType, eventData, eventId: outgoingEvent.Id, headersArguments: headers); diff --git a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusDistributedEventHandlerAdapter.cs b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusDistributedEventHandlerAdapter.cs index 7f9343ecdf..037c6e3312 100644 --- a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusDistributedEventHandlerAdapter.cs +++ b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusDistributedEventHandlerAdapter.cs @@ -14,6 +14,6 @@ public class RebusDistributedEventHandlerAdapter : IHandleMessages netstandard2.0;netstandard2.1;net7.0 + enable + Nullable Volo.Abp.EventBus Volo.Abp.EventBus $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs index 670aa6ef23..17d497f883 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs @@ -133,7 +133,7 @@ public abstract class DistributedEventBusBase : EventBusBase, IDistributedEventB Serialize(eventData), Clock.Now ); - outgoingEventInfo.SetCorrelationId(CorrelationIdProvider.Get()); + outgoingEventInfo.SetCorrelationId(CorrelationIdProvider.Get()!); await eventOutbox.EnqueueAsync(outgoingEventInfo); return true; } @@ -148,11 +148,11 @@ public abstract class DistributedEventBusBase : EventBusBase, IDistributedEventB } protected async Task AddToInboxAsync( - string messageId, + string? messageId, string eventName, Type eventType, object eventData, - [CanBeNull] string correlationId) + string? correlationId) { if (AbpDistributedEventBusOptions.Inboxes.Count <= 0) { @@ -170,7 +170,7 @@ public abstract class DistributedEventBusBase : EventBusBase, IDistributedEventB if (!messageId.IsNullOrEmpty()) { - if (await eventInbox.ExistsByMessageIdAsync(messageId)) + if (await eventInbox.ExistsByMessageIdAsync(messageId!)) { continue; } @@ -178,12 +178,12 @@ public abstract class DistributedEventBusBase : EventBusBase, IDistributedEventB var incomingEventInfo = new IncomingEventInfo( GuidGenerator.Create(), - messageId, + messageId!, eventName, Serialize(eventData), Clock.Now ); - incomingEventInfo.SetCorrelationId(correlationId); + incomingEventInfo.SetCorrelationId(correlationId!); await eventInbox.EnqueueAsync(incomingEventInfo); } } @@ -206,7 +206,7 @@ public abstract class DistributedEventBusBase : EventBusBase, IDistributedEventB await TriggerHandlersAsync(eventType, eventData); } - protected virtual async Task TriggerHandlersFromInboxAsync(Type eventType, object eventData, List exceptions, InboxConfig inboxConfig = null) + protected virtual async Task TriggerHandlersFromInboxAsync(Type eventType, object eventData, List exceptions, InboxConfig? inboxConfig = null) { await TriggerDistributedEventReceivedAsync(new DistributedEventReceived { diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs index 14e80bd9c6..e2c0a3c0c6 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs @@ -21,13 +21,13 @@ public class InboxProcessor : IInboxProcessor, ITransientDependency protected IAbpDistributedLock DistributedLock { get; } protected IUnitOfWorkManager UnitOfWorkManager { get; } protected IClock Clock { get; } - protected IEventInbox Inbox { get; private set; } - protected InboxConfig InboxConfig { get; private set; } + protected IEventInbox Inbox { get; private set; } = default!; + protected InboxConfig InboxConfig { get; private set; } = default!; protected AbpEventBusBoxesOptions EventBusBoxesOptions { get; } protected DateTime? LastCleanTime { get; set; } - protected string DistributedLockName { get; private set; } + protected string DistributedLockName { get; private set; } = default!; public ILogger Logger { get; set; } protected CancellationTokenSource StoppingTokenSource { get; } protected CancellationToken StoppingToken { get; } diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxSender.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxSender.cs index 5f34761b17..99ee06ca10 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxSender.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxSender.cs @@ -19,10 +19,10 @@ public class OutboxSender : IOutboxSender, ITransientDependency protected AbpAsyncTimer Timer { get; } protected IDistributedEventBus DistributedEventBus { get; } protected IAbpDistributedLock DistributedLock { get; } - protected IEventOutbox Outbox { get; private set; } - protected OutboxConfig OutboxConfig { get; private set; } + protected IEventOutbox Outbox { get; private set; } = default!; + protected OutboxConfig OutboxConfig { get; private set; } = default!; protected AbpEventBusBoxesOptions EventBusBoxesOptions { get; } - protected string DistributedLockName { get; private set; } + protected string DistributedLockName { get; private set; } = default!; public ILogger Logger { get; set; } protected CancellationTokenSource StoppingTokenSource { get; } diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventBusBase.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventBusBase.cs index 516a0008d7..ef5c5cdabc 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventBusBase.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventBusBase.cs @@ -131,7 +131,7 @@ public abstract class EventBusBase : IEventBus } } - protected virtual async Task TriggerHandlersAsync(Type eventType, object eventData, List exceptions, InboxConfig inboxConfig = null) + protected virtual async Task TriggerHandlersAsync(Type eventType, object eventData, List exceptions, InboxConfig? inboxConfig = null) { await new SynchronizationContextRemover(); @@ -154,7 +154,7 @@ public abstract class EventBusBase : IEventBus { var baseEventType = eventType.GetGenericTypeDefinition().MakeGenericType(baseArg); var constructorArgs = ((IEventDataWithInheritableGenericArgument)eventData).GetConstructorArgs(); - var baseEventData = Activator.CreateInstance(baseEventType, constructorArgs); + var baseEventData = Activator.CreateInstance(baseEventType, constructorArgs)!; await PublishToEventBusAsync(baseEventType, baseEventData); } } @@ -197,7 +197,7 @@ public abstract class EventBusBase : IEventBus protected abstract IEnumerable GetHandlerFactories(Type eventType); protected virtual async Task TriggerHandlerAsync(IEventHandlerFactory asyncHandlerFactory, Type eventType, - object eventData, List exceptions, InboxConfig inboxConfig = null) + object eventData, List exceptions, InboxConfig? inboxConfig = null) { using (var eventHandlerWrapper = asyncHandlerFactory.GetHandler()) { @@ -218,7 +218,7 @@ public abstract class EventBusBase : IEventBus } catch (TargetInvocationException ex) { - exceptions.Add(ex.InnerException); + exceptions.Add(ex.InnerException!); } catch (Exception ex) { diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventHandlerDisposeWrapper.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventHandlerDisposeWrapper.cs index 8a27ab84c7..eea4e662c8 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventHandlerDisposeWrapper.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventHandlerDisposeWrapper.cs @@ -6,9 +6,9 @@ public class EventHandlerDisposeWrapper : IEventHandlerDisposeWrapper { public IEventHandler EventHandler { get; } - private readonly Action _disposeAction; + private readonly Action? _disposeAction; - public EventHandlerDisposeWrapper(IEventHandler eventHandler, Action disposeAction = null) + public EventHandlerDisposeWrapper(IEventHandler eventHandler, Action? disposeAction = null) { _disposeAction = disposeAction; EventHandler = eventHandler; diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventHandlerInvoker.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventHandlerInvoker.cs index 5c7517cfe1..9ee7c6cceb 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventHandlerInvoker.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventHandlerInvoker.cs @@ -23,12 +23,12 @@ public class EventHandlerInvoker : IEventHandlerInvoker, ISingletonDependency if (typeof(ILocalEventHandler<>).MakeGenericType(eventType).IsInstanceOfType(eventHandler)) { - item.Local = (IEventHandlerMethodExecutor)Activator.CreateInstance(typeof(LocalEventHandlerMethodExecutor<>).MakeGenericType(eventType)); + item.Local = (IEventHandlerMethodExecutor?)Activator.CreateInstance(typeof(LocalEventHandlerMethodExecutor<>).MakeGenericType(eventType)); } if (typeof(IDistributedEventHandler<>).MakeGenericType(eventType).IsInstanceOfType(eventHandler)) { - item.Distributed = (IEventHandlerMethodExecutor)Activator.CreateInstance(typeof(DistributedEventHandlerMethodExecutor<>).MakeGenericType(eventType)); + item.Distributed = (IEventHandlerMethodExecutor?)Activator.CreateInstance(typeof(DistributedEventHandlerMethodExecutor<>).MakeGenericType(eventType)); } return item; diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventHandlerInvokerCacheItem.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventHandlerInvokerCacheItem.cs index 0ec617afca..e579c547de 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventHandlerInvokerCacheItem.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventHandlerInvokerCacheItem.cs @@ -2,7 +2,7 @@ public class EventHandlerInvokerCacheItem { - public IEventHandlerMethodExecutor Local { get; set; } + public IEventHandlerMethodExecutor? Local { get; set; } - public IEventHandlerMethodExecutor Distributed { get; set; } + public IEventHandlerMethodExecutor? Distributed { get; set; } } diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs index d73b2f8de9..c24627cdc5 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs @@ -105,7 +105,7 @@ public class LocalEventBus : EventBusBase, ILocalEventBus, ISingletonDependency factories.RemoveAll( factory => factory is SingleInstanceHandlerFactory && - (factory as SingleInstanceHandlerFactory).HandlerInstance == handler + ((factory as SingleInstanceHandlerFactory)!).HandlerInstance == handler ); }); } @@ -177,7 +177,7 @@ public class LocalEventBus : EventBusBase, ILocalEventBus, ISingletonDependency } // Internal for unit testing - internal Func OnEventHandleInvoking { get; set; } + internal Func? OnEventHandleInvoking { get; set; } // Internal for unit testing protected async override Task InvokeEventHandlerAsync(IEventHandler eventHandler, object eventData, Type eventType) @@ -191,7 +191,7 @@ public class LocalEventBus : EventBusBase, ILocalEventBus, ISingletonDependency } // Internal for unit testing - internal Func OnPublishing { get; set; } + internal Func? OnPublishing { get; set; } // For unit testing public async override Task PublishAsync( diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/TransientEventHandlerFactory.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/TransientEventHandlerFactory.cs index d84999cb24..75d9e26060 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/TransientEventHandlerFactory.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/TransientEventHandlerFactory.cs @@ -64,6 +64,6 @@ public class TransientEventHandlerFactory : IEventHandlerFactory protected virtual IEventHandler CreateHandler() { - return (IEventHandler)Activator.CreateInstance(HandlerType); + return (IEventHandler)Activator.CreateInstance(HandlerType)!; } }