From da2e757f711fea76688d5ba6acf23923869aba8e Mon Sep 17 00:00:00 2001 From: Dariusz Pawlukiewicz Date: Wed, 12 Feb 2020 22:43:31 +0000 Subject: [PATCH 1/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 800cff5..131a4a1 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ -Chronicle is simple **process manager/saga pattern** implementation for .NET Core that helps you manage long-living and disitrbuted transactions. +Chronicle is simple **process manager/saga pattern** implementation for .NET Core that helps you manage long-living and distirbuted transactions. | | master | develop | |---|--------|----------| From db4ab1d858c7a6dc7e5a69bc2bcfacc195087224 Mon Sep 17 00:00:00 2001 From: GooRiOn Date: Sat, 21 Mar 2020 18:54:33 +0100 Subject: [PATCH 2/7] Fixed sagas scanning. Added inner exception to exception. --- src/Chronicle/Builders/ChronicleBuilder.cs | 2 -- src/Chronicle/ChronicleException.cs | 6 ++++-- src/Chronicle/Extensions.cs | 4 ++-- src/Chronicle/IChronicleBuilder.cs | 1 - src/Chronicle/ISaga.cs | 5 +++-- src/Chronicle/Managers/SagaCoordinator.cs | 24 ++++++++-------------- src/Chronicle/Managers/SagaSeeker.cs | 1 - src/Chronicle/Saga.cs | 8 ++++---- 8 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/Chronicle/Builders/ChronicleBuilder.cs b/src/Chronicle/Builders/ChronicleBuilder.cs index c627eeb..5a4e614 100644 --- a/src/Chronicle/Builders/ChronicleBuilder.cs +++ b/src/Chronicle/Builders/ChronicleBuilder.cs @@ -1,5 +1,3 @@ -using System; -using Chronicle.Errors; using Chronicle.Persistence; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Chronicle/ChronicleException.cs b/src/Chronicle/ChronicleException.cs index d529160..b5a867f 100644 --- a/src/Chronicle/ChronicleException.cs +++ b/src/Chronicle/ChronicleException.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics.Tracing; namespace Chronicle { @@ -7,7 +6,10 @@ public class ChronicleException : Exception { public ChronicleException(string message) : base(message) { - + } + + public ChronicleException(string message, Exception innerException) : base(message, innerException) + { } } } diff --git a/src/Chronicle/Extensions.cs b/src/Chronicle/Extensions.cs index 62d3ddf..e6b6ba8 100644 --- a/src/Chronicle/Extensions.cs +++ b/src/Chronicle/Extensions.cs @@ -37,10 +37,10 @@ public static IServiceCollection AddChronicle(this IServiceCollection services, private static void RegisterSagas(this IServiceCollection services) => services.Scan(scan => { - var assembly = Assembly.GetEntryAssembly(); + var assemblies = AppDomain.CurrentDomain.GetAssemblies(); scan - .FromAssemblies(assembly) + .FromAssemblies(assemblies) .AddClasses(classes => classes.AssignableTo(typeof(ISaga))) .As(t => t .GetTypeInfo() diff --git a/src/Chronicle/IChronicleBuilder.cs b/src/Chronicle/IChronicleBuilder.cs index 3711582..c24b649 100644 --- a/src/Chronicle/IChronicleBuilder.cs +++ b/src/Chronicle/IChronicleBuilder.cs @@ -1,4 +1,3 @@ -using System; using Microsoft.Extensions.DependencyInjection; namespace Chronicle diff --git a/src/Chronicle/ISaga.cs b/src/Chronicle/ISaga.cs index fa808f0..194e9ca 100644 --- a/src/Chronicle/ISaga.cs +++ b/src/Chronicle/ISaga.cs @@ -1,3 +1,4 @@ +using System; using System.Threading.Tasks; namespace Chronicle @@ -8,8 +9,8 @@ public interface ISaga SagaStates State { get; } void Complete(); Task CompleteAsync(); - void Reject(); - Task RejectAsync(); + void Reject(Exception innerException = null); + Task RejectAsync(Exception innerException = null); void Initialize(SagaId id, SagaStates state); SagaId ResolveId(object message, ISagaContext context); } diff --git a/src/Chronicle/Managers/SagaCoordinator.cs b/src/Chronicle/Managers/SagaCoordinator.cs index 60f940f..9e877b8 100644 --- a/src/Chronicle/Managers/SagaCoordinator.cs +++ b/src/Chronicle/Managers/SagaCoordinator.cs @@ -1,11 +1,7 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Threading; using System.Threading.Tasks; using Chronicle.Async; -using Chronicle.Persistence; -using Chronicle.Utils; namespace Chronicle.Managers { @@ -17,7 +13,7 @@ internal sealed class SagaCoordinator : ISagaCoordinator private readonly ISagaPostProcessor _postProcessor; private static readonly KeyedLocker Locker = new KeyedLocker(); - public SagaCoordinator(ISagaSeeker seeker, ISagaInitializer initializer, ISagaProcessor processor, + public SagaCoordinator(ISagaSeeker seeker, ISagaInitializer initializer, ISagaProcessor processor, ISagaPostProcessor postProcessor) { _seeker = seeker; @@ -26,23 +22,21 @@ public SagaCoordinator(ISagaSeeker seeker, ISagaInitializer initializer, ISagaPr _postProcessor = postProcessor; } - public Task ProcessAsync(TMessage message, ISagaContext context = null) where TMessage : class + public Task ProcessAsync(TMessage message, ISagaContext context = null) where TMessage : class => ProcessAsync(message: message, onCompleted: null, onRejected: null, context: context); public async Task ProcessAsync(TMessage message, Func onCompleted = null, Func onRejected = null, ISagaContext context = null) where TMessage : class { var actions = _seeker.Seek().ToList(); - var sagaTasks = new List(); Task EmptyHook(TMessage m, ISagaContext ctx) => Task.CompletedTask; - onCompleted = onCompleted ?? EmptyHook; - onRejected = onRejected ?? EmptyHook; + onCompleted ??= EmptyHook; + onRejected ??= EmptyHook; - foreach (var action in actions) - { - sagaTasks.Add(ProcessAsync(message, action, onCompleted, onRejected, context)); - } + var sagaTasks = actions + .Select(action => ProcessAsync(message, action, onCompleted, onRejected, context)) + .ToList(); await Task.WhenAll(sagaTasks); } @@ -51,7 +45,7 @@ private async Task ProcessAsync(TMessage message, ISagaAction onCompleted, Func onRejected, ISagaContext context = null) where TMessage : class { - context = context ?? SagaContext.Empty; + context ??= SagaContext.Empty; var saga = (ISaga)action; var id = saga.ResolveId(message, context); @@ -63,7 +57,7 @@ private async Task ProcessAsync(TMessage message, ISagaAction Date: Sat, 21 Mar 2020 18:54:57 +0100 Subject: [PATCH 3/7] 3.2.0 --- src/Chronicle/Chronicle.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Chronicle/Chronicle.csproj b/src/Chronicle/Chronicle.csproj index 062f135..ebded55 100644 --- a/src/Chronicle/Chronicle.csproj +++ b/src/Chronicle/Chronicle.csproj @@ -11,10 +11,10 @@ https://github.com/chronicle-stack/Chronicle https://github.com/chronicle-stack/Chronicle/blob/master/LICENSE https://avatars1.githubusercontent.com/u/42150754?s=200 - 3.1.0 - 3.1.0 - 3.1.0.0 - 3.1.0.0 + 3.2.0 + 3.2.0 + 3.2.0.0 + 3.2.0.0 latest From c1e779e0fcb9fbc3d5d42f1595ed17be386f0b9c Mon Sep 17 00:00:00 2001 From: GooRiOn Date: Sat, 21 Mar 2020 18:57:46 +0100 Subject: [PATCH 4/7] Upadted README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 131a4a1..878de6b 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,12 @@ Chronicle is simple **process manager/saga pattern** implementation for .NET Cor Chornicle is available on [NuGet](https://www.nuget.org/packages/Chronicle_/) ### Package manager ```bash -Install-Package Chronicle_ -Version 3.1.0 +Install-Package Chronicle_ -Version 3.2.0 ``` ### .NET CLI ```bash -dotnet add package Chronicle_ --version 3.1.0 +dotnet add package Chronicle_ --version 3.2.0 ``` # Getting started From 3f76dfb96ff315c13810cca36e7ba4bf31a27cd6 Mon Sep 17 00:00:00 2001 From: GooRiOn Date: Sat, 21 Mar 2020 21:48:00 +0100 Subject: [PATCH 5/7] Fixed inner exception --- src/Chronicle/Chronicle.csproj | 8 ++++---- src/Chronicle/Managers/SagaProcessor.cs | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Chronicle/Chronicle.csproj b/src/Chronicle/Chronicle.csproj index ebded55..aa237dc 100644 --- a/src/Chronicle/Chronicle.csproj +++ b/src/Chronicle/Chronicle.csproj @@ -11,10 +11,10 @@ https://github.com/chronicle-stack/Chronicle https://github.com/chronicle-stack/Chronicle/blob/master/LICENSE https://avatars1.githubusercontent.com/u/42150754?s=200 - 3.2.0 - 3.2.0 - 3.2.0.0 - 3.2.0.0 + 3.2.1 + 3.2.1 + 3.2.1.0 + 3.2.1.0 latest diff --git a/src/Chronicle/Managers/SagaProcessor.cs b/src/Chronicle/Managers/SagaProcessor.cs index 0643407..98e4d4b 100644 --- a/src/Chronicle/Managers/SagaProcessor.cs +++ b/src/Chronicle/Managers/SagaProcessor.cs @@ -14,8 +14,8 @@ public SagaProcessor(ISagaStateRepository repository, ISagaLog log) _repository = repository; _log = log; } - - public async Task ProcessAsync(ISaga saga, TMessage message, ISagaState state, + + public async Task ProcessAsync(ISaga saga, TMessage message, ISagaState state, ISagaContext context) where TMessage : class { var action = (ISagaAction)saga; @@ -24,13 +24,13 @@ public async Task ProcessAsync(ISaga saga, TMessage message, ISagaStat { await action.HandleAsync(message, context); } - catch (Exception e) + catch (Exception ex) { - context.SagaContextError = new SagaContextError(e); + context.SagaContextError = new SagaContextError(ex); if (!(saga.State is SagaStates.Rejected)) { - saga.Reject(); + saga.Reject(ex); } } finally @@ -38,7 +38,7 @@ public async Task ProcessAsync(ISaga saga, TMessage message, ISagaStat await UpdateSagaAsync(message, saga, state); } } - + private async Task UpdateSagaAsync(TMessage message, ISaga saga, ISagaState state) where TMessage : class { @@ -51,7 +51,7 @@ private async Task UpdateSagaAsync(TMessage message, ISaga saga, ISaga var persistenceTasks = new [] { - _repository.WriteAsync(state), + _repository.WriteAsync(state), _log.WriteAsync(logData) }; From 5e941629264b1d0630cc3ef41e7faa7d6218c103 Mon Sep 17 00:00:00 2001 From: GooRiOn Date: Sat, 21 Mar 2020 21:50:19 +0100 Subject: [PATCH 6/7] 3.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 878de6b..8bf7360 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,12 @@ Chronicle is simple **process manager/saga pattern** implementation for .NET Cor Chornicle is available on [NuGet](https://www.nuget.org/packages/Chronicle_/) ### Package manager ```bash -Install-Package Chronicle_ -Version 3.2.0 +Install-Package Chronicle_ -Version 3.2.1 ``` ### .NET CLI ```bash -dotnet add package Chronicle_ --version 3.2.0 +dotnet add package Chronicle_ --version 3.2.1 ``` # Getting started From fc1ae7fce09fbe65132342075ee8f2c3471a5592 Mon Sep 17 00:00:00 2001 From: GooRiOn Date: Thu, 20 Aug 2020 09:54:28 +0200 Subject: [PATCH 7/7] Fixed type in mongo saga state --- .../src/Chronicle.Integrations.MongoDB.csproj | 8 ++++---- .../src/Persistence/MongoSagaState.cs | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Chronicle.Integrations.MongoDB/src/Chronicle.Integrations.MongoDB.csproj b/src/Chronicle.Integrations.MongoDB/src/Chronicle.Integrations.MongoDB.csproj index ba633bb..8954157 100644 --- a/src/Chronicle.Integrations.MongoDB/src/Chronicle.Integrations.MongoDB.csproj +++ b/src/Chronicle.Integrations.MongoDB/src/Chronicle.Integrations.MongoDB.csproj @@ -11,10 +11,10 @@ https://github.com/chronicle-stack/Chronicle.Integrations.MongoDB https://github.com/chronicle-stack/Chronicle/blob/master/LICENSE https://avatars1.githubusercontent.com/u/42150754?s=200 - 3.1.0 - 3.1.0 - 3.1.0 - 3.1.0 + 3.1.1 + 3.1.1 + 3.1.1 + 3.1.1 diff --git a/src/Chronicle.Integrations.MongoDB/src/Persistence/MongoSagaState.cs b/src/Chronicle.Integrations.MongoDB/src/Persistence/MongoSagaState.cs index bd8191b..31bcb7c 100644 --- a/src/Chronicle.Integrations.MongoDB/src/Persistence/MongoSagaState.cs +++ b/src/Chronicle.Integrations.MongoDB/src/Persistence/MongoSagaState.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Reflection; using MongoDB.Bson.Serialization.Attributes; @@ -15,7 +16,12 @@ internal class MongoSagaState : ISagaState public string SagaType { get; set; } public SagaStates State { get; set; } public object Data { get; set; } - Type ISagaState.Type => Assembly.GetEntryAssembly()?.GetType(SagaType); + + Type ISagaState.Type => _type ??= AppDomain.CurrentDomain.GetAssemblies() + .Select(a => a.GetType(SagaType)) + .FirstOrDefault(t => t is {}); + + private Type _type; public void Update(SagaStates state, object data = null) {