mirror of https://github.com/abpframework/abp.git
1 changed files with 26 additions and 7 deletions
@ -1,25 +1,44 @@ |
|||
using Dapr.Client; |
|||
using System.Collections.Concurrent; |
|||
using System.Text.Json; |
|||
using Dapr.Client; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Json.SystemTextJson; |
|||
|
|||
namespace Volo.Abp.Dapr; |
|||
|
|||
public class AbpDaprClientFactory : ITransientDependency |
|||
{ |
|||
protected AbpDaprOptions Options { get; } |
|||
protected AbpSystemTextJsonSerializerOptions SystemTextJsonSerializerOptions { get; } |
|||
|
|||
public AbpDaprClientFactory(IOptions<AbpDaprOptions> options) |
|||
public AbpDaprClientFactory( |
|||
IOptions<AbpDaprOptions> options, |
|||
IOptions<AbpSystemTextJsonSerializerOptions> systemTextJsonSerializerOptions) |
|||
{ |
|||
Options = options.Value; |
|||
SystemTextJsonSerializerOptions = systemTextJsonSerializerOptions.Value; |
|||
} |
|||
|
|||
public virtual Task<DaprClient> CreateAsync() |
|||
public virtual async Task<DaprClient> CreateAsync() |
|||
{ |
|||
var daprClient = new DaprClientBuilder() |
|||
var builder = new DaprClientBuilder() |
|||
.UseHttpEndpoint(Options.HttpEndpoint) |
|||
//.UseJsonSerializationOptions()//TODO: Use abp JsonSerializerOptions
|
|||
.Build(); |
|||
.UseJsonSerializationOptions(await CreateJsonSerializerOptions()); |
|||
|
|||
return Task.FromResult(daprClient); |
|||
if (!Options.GrpcEndpoint.IsNullOrWhiteSpace()) |
|||
{ |
|||
builder.UseGrpcEndpoint(Options.GrpcEndpoint); |
|||
} |
|||
|
|||
return builder.Build(); |
|||
} |
|||
|
|||
private readonly static ConcurrentDictionary<string, JsonSerializerOptions> JsonSerializerOptionsCache = new ConcurrentDictionary<string, JsonSerializerOptions>(); |
|||
|
|||
protected virtual Task<JsonSerializerOptions> CreateJsonSerializerOptions() |
|||
{ |
|||
return Task.FromResult(JsonSerializerOptionsCache.GetOrAdd(nameof(AbpDaprClientFactory), |
|||
_ => new JsonSerializerOptions(SystemTextJsonSerializerOptions.JsonSerializerOptions))); |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue