-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from mizrael/maintenance
updated initial State creation
- Loading branch information
Showing
52 changed files
with
562 additions
and
798 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
src/OpenSleigh.Core/DependencyInjection/ISagaStateFactory.cs
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
src/OpenSleigh.Core/DependencyInjection/LambdaSagaStateFactory.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using OpenSleigh.Core.Exceptions; | ||
using OpenSleigh.Core.Messaging; | ||
|
||
namespace OpenSleigh.Core | ||
{ | ||
public interface ISagaStateFactory<in TM, out TD> : ISagaStateFactory<TD> | ||
where TM : IMessage | ||
where TD : SagaState | ||
{ | ||
TD Create(TM message); | ||
} | ||
|
||
public interface ISagaStateFactory<out TD> where TD : SagaState | ||
{ | ||
TD Create(IMessage message); | ||
} | ||
|
||
internal class DefaultSagaStateFactory<TD> : ISagaStateFactory<TD> | ||
where TD : SagaState | ||
{ | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
public DefaultSagaStateFactory(IServiceProvider serviceProvider) | ||
{ | ||
_serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); | ||
} | ||
|
||
public TD Create(IMessage message) | ||
{ | ||
if (message == null) | ||
throw new ArgumentNullException(nameof(message)); | ||
|
||
var messageType = message.GetType(); | ||
var stateType = typeof(TD); | ||
|
||
var factoryInterfaceType = typeof(ISagaStateFactory<,>).MakeGenericType(messageType, stateType); | ||
var factory = _serviceProvider.GetService(factoryInterfaceType) as ISagaStateFactory<TD>; | ||
if (null == factory) | ||
throw new StateCreationException( | ||
$"no state factory registered for message type '{message.GetType().FullName}'"); | ||
|
||
var state = factory.Create((dynamic) message); | ||
return state; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using OpenSleigh.Core.Messaging; | ||
|
||
namespace OpenSleigh.Core | ||
{ | ||
internal class LambdaSagaStateFactory<TM, TD> : ISagaStateFactory<TM, TD> | ||
where TM : IMessage | ||
where TD : SagaState | ||
{ | ||
private readonly Func<TM, TD> _factory; | ||
|
||
public LambdaSagaStateFactory(Func<TM, TD> factory) | ||
{ | ||
_factory = factory ?? throw new ArgumentNullException(nameof(factory)); | ||
} | ||
|
||
public TD Create(TM message) => _factory(message); | ||
|
||
public TD Create(IMessage message) | ||
{ | ||
if (message is TM m) | ||
return _factory(m); | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/OpenSleigh.Persistence.InMemory/InMemorySagaConfiguratorExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.