From 0064f4f501a15ac86f7433aeb4dbdd9495fa938e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 14 Sep 2022 11:00:17 +0300 Subject: [PATCH] Introduce IAbpDaprClientFactory.CreateHttpClientAsync Also improved the CreateAsync method. --- .../Volo/Abp/Dapr/AbpDaprClientFactory.cs | 15 ++++++++++++++- .../Volo/Abp/Dapr/IAbpDaprClientFactory.cs | 8 +++++++- .../Dapr/DaprAbpDistributedLock.cs | 4 ++-- .../Abp/EventBus/Dapr/DaprDistributedEventBus.cs | 4 ++-- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/framework/src/Volo.Abp.Dapr/Volo/Abp/Dapr/AbpDaprClientFactory.cs b/framework/src/Volo.Abp.Dapr/Volo/Abp/Dapr/AbpDaprClientFactory.cs index ed04aa9b03..b7419153ff 100644 --- a/framework/src/Volo.Abp.Dapr/Volo/Abp/Dapr/AbpDaprClientFactory.cs +++ b/framework/src/Volo.Abp.Dapr/Volo/Abp/Dapr/AbpDaprClientFactory.cs @@ -24,7 +24,7 @@ public class AbpDaprClientFactory : IAbpDaprClientFactory, ISingletonDependency return new JsonSerializerOptions(systemTextJsonSerializerOptions.JsonSerializerOptions); } - public virtual Task CreateAsync() + public virtual Task CreateAsync(Action? builderAction = null) { var builder = new DaprClientBuilder() .UseJsonSerializationOptions(JsonSerializerOptions); @@ -39,6 +39,19 @@ public class AbpDaprClientFactory : IAbpDaprClientFactory, ISingletonDependency builder.UseGrpcEndpoint(DaprOptions.GrpcEndpoint); } + builderAction?.Invoke(builder); + return Task.FromResult(builder.Build()); } + + public Task CreateHttpClientAsync(string? appId = null, string? daprEndpoint = null, string? daprApiToken = null) + { + if(daprEndpoint.IsNullOrWhiteSpace() && + !DaprOptions.HttpEndpoint.IsNullOrWhiteSpace()) + { + daprEndpoint = DaprOptions.HttpEndpoint; + } + + return Task.FromResult(DaprClient.CreateInvokeHttpClient(appId, daprEndpoint, daprApiToken)); + } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Dapr/Volo/Abp/Dapr/IAbpDaprClientFactory.cs b/framework/src/Volo.Abp.Dapr/Volo/Abp/Dapr/IAbpDaprClientFactory.cs index 12dc15bb67..cd2916ae5a 100644 --- a/framework/src/Volo.Abp.Dapr/Volo/Abp/Dapr/IAbpDaprClientFactory.cs +++ b/framework/src/Volo.Abp.Dapr/Volo/Abp/Dapr/IAbpDaprClientFactory.cs @@ -4,5 +4,11 @@ namespace Volo.Abp.Dapr; public interface IAbpDaprClientFactory { - Task CreateAsync(); + Task CreateAsync(Action? builderAction = null); + + Task CreateHttpClientAsync( + string? appId = null, + string? daprEndpoint = null, + string? daprApiToken = null + ); } \ No newline at end of file diff --git a/framework/src/Volo.Abp.DistributedLocking.Dapr/Volo/Abp/DistributedLocking/Dapr/DaprAbpDistributedLock.cs b/framework/src/Volo.Abp.DistributedLocking.Dapr/Volo/Abp/DistributedLocking/Dapr/DaprAbpDistributedLock.cs index b4116c105c..7221775fd1 100644 --- a/framework/src/Volo.Abp.DistributedLocking.Dapr/Volo/Abp/DistributedLocking/Dapr/DaprAbpDistributedLock.cs +++ b/framework/src/Volo.Abp.DistributedLocking.Dapr/Volo/Abp/DistributedLocking/Dapr/DaprAbpDistributedLock.cs @@ -7,13 +7,13 @@ namespace Volo.Abp.DistributedLocking.Dapr; [Dependency(ReplaceServices = true)] public class DaprAbpDistributedLock : IAbpDistributedLock, ITransientDependency { - protected AbpDaprClientFactory DaprClientFactory { get; } + protected IAbpDaprClientFactory DaprClientFactory { get; } protected AbpDistributedLockDaprOptions DistributedLockDaprOptions { get; } protected AbpDaprOptions DaprOptions { get; } protected IDistributedLockKeyNormalizer DistributedLockKeyNormalizer { get; } public DaprAbpDistributedLock( - AbpDaprClientFactory daprClientFactory, + IAbpDaprClientFactory daprClientFactory, IOptions distributedLockDaprOptions, IOptions daprOptions, IDistributedLockKeyNormalizer distributedLockKeyNormalizer) 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 1f241b9c6d..19ff820877 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 @@ -18,7 +18,7 @@ public class DaprDistributedEventBus : DistributedEventBusBase, ISingletonDepend { protected IDaprSerializer Serializer { get; } protected AbpDaprEventBusOptions DaprEventBusOptions { get; } - protected AbpDaprClientFactory DaprClientFactory { get; } + protected IAbpDaprClientFactory DaprClientFactory { get; } protected ConcurrentDictionary> HandlerFactories { get; } protected ConcurrentDictionary EventTypes { get; } @@ -33,7 +33,7 @@ public class DaprDistributedEventBus : DistributedEventBusBase, ISingletonDepend IEventHandlerInvoker eventHandlerInvoker, IDaprSerializer serializer, IOptions daprEventBusOptions, - AbpDaprClientFactory daprClientFactory) + IAbpDaprClientFactory daprClientFactory) : base(serviceScopeFactory, currentTenant, unitOfWorkManager, abpDistributedEventBusOptions, guidGenerator, clock, eventHandlerInvoker) { Serializer = serializer;