(feature): dependencies update
This commit is contained in:
parent
5327b19e04
commit
e7565ac843
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 Maksym Sadovnychyy (MAKS-IT)
|
Copyright (c) 2024 - 2025 Maksym Sadovnychyy (MAKS-IT)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -1,14 +1,26 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using MaksIT.Dapr.Services;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
|
||||||
namespace MaksIT.Dapr.Extensions;
|
namespace MaksIT.Dapr.Extensions;
|
||||||
|
|
||||||
public static class ServiceCollectionExtensions {
|
public static class ServiceCollectionExtensions {
|
||||||
public static void RegisterPublisher(this IServiceCollection services) {
|
private static bool _isDaprClientRegistered = false;
|
||||||
|
|
||||||
|
private static void AddDaprClientOnce(this IServiceCollection services) {
|
||||||
|
if (!_isDaprClientRegistered) {
|
||||||
services.AddDaprClient();
|
services.AddDaprClient();
|
||||||
services.AddSingleton<IDaprPublisherService, DaprService>();
|
_isDaprClientRegistered = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RegisterPublisher(this IServiceCollection services) {
|
||||||
|
services.AddDaprClientOnce();
|
||||||
|
services.AddSingleton<IDaprPublisherService, DaprPublisherService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RegisterStateStore(this IServiceCollection services) {
|
public static void RegisterStateStore(this IServiceCollection services) {
|
||||||
services.AddDaprClient();
|
services.AddDaprClientOnce();
|
||||||
services.AddSingleton<IDaprStateStoreService, DaprService>();
|
services.AddSingleton<IDaprStateStoreService, DaprStateStoreService>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<!-- NuGet package metadata -->
|
<!-- NuGet package metadata -->
|
||||||
<PackageId>MaksIT.Dapr</PackageId>
|
<PackageId>MaksIT.Dapr</PackageId>
|
||||||
<Version>1.0.7</Version>
|
<Version>1.0.8</Version>
|
||||||
<Authors>Maksym Sadovnychyy</Authors>
|
<Authors>Maksym Sadovnychyy</Authors>
|
||||||
<Company>MAKS-IT</Company>
|
<Company>MAKS-IT</Company>
|
||||||
<Product>MaksIT.Dapr</Product>
|
<Product>MaksIT.Dapr</Product>
|
||||||
@ -17,16 +17,20 @@
|
|||||||
<License>MIT</License>
|
<License>MIT</License>
|
||||||
<RequireLicenseAcceptance>false</RequireLicenseAcceptance>
|
<RequireLicenseAcceptance>false</RequireLicenseAcceptance>
|
||||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
|
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="../../README.md" Pack="true" PackagePath="" />
|
<None Include="../../README.md" Pack="true" PackagePath="" />
|
||||||
|
<None Include="../../LICENSE.md" Pack="true" PackagePath="" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Dapr.Actors.AspNetCore" Version="1.15.4" />
|
<PackageReference Include="Dapr.Actors.AspNetCore" Version="1.16.0" />
|
||||||
<PackageReference Include="Dapr.AspNetCore" Version="1.15.4" />
|
<PackageReference Include="Dapr.AspNetCore" Version="1.16.0" />
|
||||||
<PackageReference Include="MaksIT.Results" Version="1.0.6" />
|
<PackageReference Include="Dapr.Workflow" Version="1.16.0" />
|
||||||
|
<PackageReference Include="MaksIT.Core" Version="1.5.1" />
|
||||||
|
<PackageReference Include="MaksIT.Results" Version="1.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
37
src/MaksIT.Dapr/Services/DaprPublisherService.cs
Normal file
37
src/MaksIT.Dapr/Services/DaprPublisherService.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
using Dapr.Client;
|
||||||
|
|
||||||
|
using MaksIT.Results;
|
||||||
|
using MaksIT.Core.Extensions;
|
||||||
|
|
||||||
|
namespace MaksIT.Dapr.Services;
|
||||||
|
public interface IDaprPublisherService {
|
||||||
|
Task<Result> PublishEventAsync(string pubsubName, string topicName, object payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DaprPublisherService : IDaprPublisherService {
|
||||||
|
private const string _errorMessage = "MaksIT.Dapr - Event publishing error";
|
||||||
|
|
||||||
|
private readonly DaprClient _client;
|
||||||
|
private readonly ILogger<DaprPublisherService> _logger;
|
||||||
|
|
||||||
|
public DaprPublisherService(
|
||||||
|
ILogger<DaprPublisherService> logger,
|
||||||
|
DaprClient client
|
||||||
|
) {
|
||||||
|
_logger = logger;
|
||||||
|
_client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Result> PublishEventAsync(string pubsubName, string topicName, object payload) {
|
||||||
|
try {
|
||||||
|
await _client.PublishEventAsync(pubsubName, topicName, payload);
|
||||||
|
return Result.Ok();
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
_logger.LogError(ex, _errorMessage);
|
||||||
|
return Result.InternalServerError([_errorMessage, .. ex.ExtractMessages()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,61 +3,29 @@
|
|||||||
using Dapr.Client;
|
using Dapr.Client;
|
||||||
|
|
||||||
using MaksIT.Results;
|
using MaksIT.Results;
|
||||||
|
using MaksIT.Core.Extensions;
|
||||||
|
|
||||||
namespace MaksIT.Dapr;
|
namespace MaksIT.Dapr.Services;
|
||||||
|
|
||||||
public interface IDaprPublisherService {
|
|
||||||
Task<Result> PublishEventAsync(string pubSubName, string topicName, string payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IDaprStateStoreService {
|
public interface IDaprStateStoreService {
|
||||||
Task<Result> SetStateAsync<T>(string storeName, string key, T value);
|
Task<Result> SetStateAsync<T>(string storeName, string key, T value);
|
||||||
Task<Result<T?>> GetStateAsync<T>(string storeName, string key);
|
Task<Result<T?>> GetStateAsync<T>(string storeName, string key);
|
||||||
Task<Result> DeleteStateAsync(string storeName, string key);
|
Task<Result> DeleteStateAsync(string storeName, string key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DaprService : IDaprPublisherService, IDaprStateStoreService {
|
|
||||||
|
public class DaprStateStoreService : IDaprStateStoreService {
|
||||||
private const string _errorMessage = "MaksIT.Dapr - Data provider error";
|
private const string _errorMessage = "MaksIT.Dapr - Data provider error";
|
||||||
|
|
||||||
private readonly DaprClient _client;
|
private readonly DaprClient _client;
|
||||||
private readonly ILogger<DaprService> _logger;
|
private readonly ILogger<DaprStateStoreService> _logger;
|
||||||
|
|
||||||
public DaprService(
|
public DaprStateStoreService(
|
||||||
ILogger<DaprService> logger,
|
ILogger<DaprStateStoreService> logger,
|
||||||
DaprClient client
|
DaprClient client
|
||||||
) {
|
) {
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_client = client;
|
_client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Publishes an event to a Dapr topic
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="pubSubName"></param>
|
|
||||||
/// <param name="topicName"></param>
|
|
||||||
/// <param name="payload"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<Result> PublishEventAsync(string pubSubName, string topicName, string payload) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
var traceId = System.Diagnostics.Activity.Current?.TraceId.ToString();
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(traceId)) {
|
|
||||||
var metadata = new Dictionary<string, string> { ["traceid"] = traceId };
|
|
||||||
await _client.PublishEventAsync(pubSubName, topicName, payload, metadata);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
await _client.PublishEventAsync(pubSubName, topicName, payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result.Ok();
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
_logger.LogError(ex, _errorMessage);
|
|
||||||
return Result.InternalServerError(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves a state to a Dapr state store
|
/// Saves a state to a Dapr state store
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -73,7 +41,7 @@ public class DaprService : IDaprPublisherService, IDaprStateStoreService {
|
|||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
_logger.LogError(ex, _errorMessage);
|
_logger.LogError(ex, _errorMessage);
|
||||||
return Result.InternalServerError(ex.Message);
|
return Result.InternalServerError(new[] {_errorMessage}.Concat(ex.ExtractMessages()).ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +62,7 @@ public class DaprService : IDaprPublisherService, IDaprStateStoreService {
|
|||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
_logger.LogError(ex, _errorMessage);
|
_logger.LogError(ex, _errorMessage);
|
||||||
return Result<T?>.InternalServerError(default, ex.Message);
|
return Result<T?>.InternalServerError(default, new[] {_errorMessage}.Concat(ex.ExtractMessages()).ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +79,7 @@ public class DaprService : IDaprPublisherService, IDaprStateStoreService {
|
|||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
_logger.LogError(ex, _errorMessage);
|
_logger.LogError(ex, _errorMessage);
|
||||||
return Result.InternalServerError(ex.Message);
|
return Result.InternalServerError([_errorMessage, .. ex.ExtractMessages()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user