Browse Source

Introduce IAbpDaprClientFactory.CreateHttpClientAsync

Also improved the CreateAsync method.
pull/14015/head
Halil İbrahim Kalkan 4 years ago
parent
commit
0064f4f501
  1. 15
      framework/src/Volo.Abp.Dapr/Volo/Abp/Dapr/AbpDaprClientFactory.cs
  2. 8
      framework/src/Volo.Abp.Dapr/Volo/Abp/Dapr/IAbpDaprClientFactory.cs
  3. 4
      framework/src/Volo.Abp.DistributedLocking.Dapr/Volo/Abp/DistributedLocking/Dapr/DaprAbpDistributedLock.cs
  4. 4
      framework/src/Volo.Abp.EventBus.Dapr/Volo/Abp/EventBus/Dapr/DaprDistributedEventBus.cs

15
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<DaprClient> CreateAsync()
public virtual Task<DaprClient> CreateAsync(Action<DaprClientBuilder>? 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<HttpClient> 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));
}
}

8
framework/src/Volo.Abp.Dapr/Volo/Abp/Dapr/IAbpDaprClientFactory.cs

@ -4,5 +4,11 @@ namespace Volo.Abp.Dapr;
public interface IAbpDaprClientFactory
{
Task<DaprClient> CreateAsync();
Task<DaprClient> CreateAsync(Action<DaprClientBuilder>? builderAction = null);
Task<HttpClient> CreateHttpClientAsync(
string? appId = null,
string? daprEndpoint = null,
string? daprApiToken = null
);
}

4
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<AbpDistributedLockDaprOptions> distributedLockDaprOptions,
IOptions<AbpDaprOptions> daprOptions,
IDistributedLockKeyNormalizer distributedLockKeyNormalizer)

4
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<Type, List<IEventHandlerFactory>> HandlerFactories { get; }
protected ConcurrentDictionary<string, Type> EventTypes { get; }
@ -33,7 +33,7 @@ public class DaprDistributedEventBus : DistributedEventBusBase, ISingletonDepend
IEventHandlerInvoker eventHandlerInvoker,
IDaprSerializer serializer,
IOptions<AbpDaprEventBusOptions> daprEventBusOptions,
AbpDaprClientFactory daprClientFactory)
IAbpDaprClientFactory daprClientFactory)
: base(serviceScopeFactory, currentTenant, unitOfWorkManager, abpDistributedEventBusOptions, guidGenerator, clock, eventHandlerInvoker)
{
Serializer = serializer;

Loading…
Cancel
Save