Skip to content

Commit

Permalink
Merge pull request #1 from Shuttle/ms-di
Browse files Browse the repository at this point in the history
- Microsoft dependency injection / options
  • Loading branch information
eben-roux authored Sep 1, 2022
2 parents c34bb79 + 3b587b6 commit 4e28ae2
Show file tree
Hide file tree
Showing 37 changed files with 519 additions and 333 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ Process management for Shuttle.Esb endpoints using Shuttle.Recall event sourcing

[Shuttle.Esb Samples](https://github.com/Shuttle/Shuttle.Esb.Samples)

# Registration / Activation
# Configuration

The required components may be registered by calling `ComponentRegistryExtensions.RegisterProcessManagement(IComponentRegistry)`.
Add the process management services to the `IServiceCollection` as follows:

In order to activate the process managgement functionality you may call `ComponentResolverExtensions.ResolveProcessManagement(IComponentResolver)`.
```c#
services.AddProcessManagement(builder => {
builder.AddAssembly(assembly);
builder.AddAssembly("assemblyName");
});
```

The `builder.AddAssembly()` method will result in all classes that implement `IProcessMessageAssessor` being added to the `IMessageHandlingAssessor` as well as registering the appropriate mappings in the `ProcessActivator` of the `IProcessMessageHandler<>` and `IProcessStartMessageHandler<>` interface implementations.
49 changes: 29 additions & 20 deletions Shuttle.Esb.Process.Tests/DefaultProcessActivatorFixture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Extensions.Options;
using NUnit.Framework;

namespace Shuttle.Esb.Process.Tests
Expand All @@ -10,18 +11,20 @@ public class DefaultProcessActivatorFixture
public void Should_be_able_to_request_mapping_registration()
{
var transportMessage = new TransportMessage();
var activator = new DefaultProcessActivator();

activator.RegisterMappings();
var processManagementOptions = new ProcessManagementOptions();
processManagementOptions.AssemblyNames.Add("Shuttle.Esb.Process.Tests");

var activator = new ProcessActivator(Options.Create(processManagementOptions));

Assert.IsFalse(activator.IsProcessMessage(transportMessage, new MockNullCommand()));

Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockRegisterOrderCommand()));
Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockEMailSentEvent()));
Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockCompleteOrderCommand()));
Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockRegisterOrder()));
Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockEMailSent()));
Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockCompleteOrder()));

Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockRegisterMemberCommand()));
Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockCompleteMemberRegistrationCommand()));
Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockRegisterMember()));
Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockCompleteMemberRegistration()));
}

[Test]
Expand All @@ -32,14 +35,15 @@ public void Should_be_able_to_resolve_message_to_multiple_processes()
CorrelationId = Guid.NewGuid().ToString()
};

var activator = new DefaultProcessActivator();
var processManagementOptions = new ProcessManagementOptions();
processManagementOptions.AssemblyNames.Add("Shuttle.Esb.Process.Tests");

activator.RegisterMappings();
var activator = new ProcessActivator(Options.Create(processManagementOptions));

activator.RegisterResolver<MockEMailSentEvent>(
activator.RegisterResolver<MockEMailSent>(
(transport, message) => new MessageProcessType(typeof (MockOrderProcess), false));

var instance = activator.Create(transportMessage, new MockEMailSentEvent());
var instance = activator.Create(transportMessage, new MockEMailSent());

Assert.IsTrue(instance.GetType() == typeof (MockOrderProcess));
}
Expand All @@ -48,34 +52,39 @@ public void Should_be_able_to_resolve_message_to_multiple_processes()
public void Should_be_able_to_start_process()
{
var transportMessage = new TransportMessage();
var activator = new DefaultProcessActivator();

activator.RegisterMappings();
var processManagementOptions = new ProcessManagementOptions();
processManagementOptions.AssemblyNames.Add("Shuttle.Esb.Process.Tests");

var activator = new ProcessActivator(Options.Create(processManagementOptions));

Assert.IsTrue(typeof (MockOrderProcess) ==
activator.Create(transportMessage, new MockRegisterOrderCommand()).GetType());
activator.Create(transportMessage, new MockRegisterOrder()).GetType());
Assert.IsTrue(typeof (MockMemberRegistrationProcess) ==
activator.Create(transportMessage, new MockRegisterMemberCommand()).GetType());
activator.Create(transportMessage, new MockRegisterMember()).GetType());
}

[Test]
public void Should_throw_exception_when_creating_unknown_process()
{
var transportMessage = new TransportMessage();
var activator = new DefaultProcessActivator();

Assert.Throws<ProcessException>(() => activator.Create(transportMessage, new MockRegisterMemberCommand()));
var activator = new ProcessActivator(Options.Create(new ProcessManagementOptions()));

Assert.Throws<ProcessException>(() => activator.Create(transportMessage, new MockNullCommand()));
}

[Test]
public void Should_throw_exception_when_no_resolver_for_message_to_multiple_processes()
{
var transportMessage = new TransportMessage();
var activator = new DefaultProcessActivator();

activator.RegisterMappings();
var processManagementOptions = new ProcessManagementOptions();
processManagementOptions.AssemblyNames.Add("Shuttle.Esb.Process.Tests");

var activator = new ProcessActivator(Options.Create(processManagementOptions));

Assert.Throws<ProcessException>(() => activator.Create(transportMessage, new MockEMailSentEvent()));
Assert.Throws<ProcessException>(() => activator.Create(transportMessage, new MockEMailSent()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Shuttle.Esb.Process.Tests
{
public class MockCompleteMemberRegistration
{
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Shuttle.Esb.Process.Tests
{
public class MockEMailSentEvent
public class MockCompleteOrder
{
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Shuttle.Esb.Process.Tests
{
public class MockRegisterOrderCommand
public class MockEMailSent
{
}
}
12 changes: 6 additions & 6 deletions Shuttle.Esb.Process.Tests/Mocks/MockMemberRegistrationProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ namespace Shuttle.Esb.Process.Tests
{
public class MockMemberRegistrationProcess :
IProcessManager,
IProcessStartMessageHandler<MockRegisterMemberCommand>,
IProcessMessageHandler<MockEMailSentEvent>,
IProcessMessageHandler<MockCompleteMemberRegistrationCommand>
IProcessStartMessageHandler<MockRegisterMember>,
IProcessMessageHandler<MockEMailSent>,
IProcessMessageHandler<MockCompleteMemberRegistration>
{
public Guid CorrelationId { get; set; }

public void ProcessMessage(IProcessHandlerContext<MockCompleteMemberRegistrationCommand> context)
public void ProcessMessage(IProcessHandlerContext<MockCompleteMemberRegistration> context)
{
throw new NotImplementedException();
}

public void ProcessMessage(IProcessHandlerContext<MockEMailSentEvent> context)
public void ProcessMessage(IProcessHandlerContext<MockEMailSent> context)
{
throw new NotImplementedException();
}

public void ProcessMessage(IProcessHandlerContext<MockRegisterMemberCommand> context)
public void ProcessMessage(IProcessHandlerContext<MockRegisterMember> context)
{
throw new NotImplementedException();
}
Expand Down
12 changes: 6 additions & 6 deletions Shuttle.Esb.Process.Tests/Mocks/MockOrderProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ namespace Shuttle.Esb.Process.Tests
{
public class MockOrderProcess :
IProcessManager,
IProcessStartMessageHandler<MockRegisterOrderCommand>,
IProcessMessageHandler<MockEMailSentEvent>,
IProcessMessageHandler<MockCompleteOrderCommand>
IProcessStartMessageHandler<MockRegisterOrder>,
IProcessMessageHandler<MockEMailSent>,
IProcessMessageHandler<MockCompleteOrder>
{
public Guid CorrelationId { get; set; }

public void ProcessMessage(IProcessHandlerContext<MockCompleteOrderCommand> context)
public void ProcessMessage(IProcessHandlerContext<MockCompleteOrder> context)
{
throw new NotImplementedException();
}

public void ProcessMessage(IProcessHandlerContext<MockEMailSentEvent> context)
public void ProcessMessage(IProcessHandlerContext<MockEMailSent> context)
{
throw new NotImplementedException();
}

public void ProcessMessage(IProcessHandlerContext<MockRegisterOrderCommand> context)
public void ProcessMessage(IProcessHandlerContext<MockRegisterOrder> context)
{
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Shuttle.Esb.Process.Tests
{
public class MockCompleteOrderCommand
public class MockRegisterMember
{
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Shuttle.Esb.Process.Tests
{
public class MockRegisterMemberCommand
public class MockRegisterOrder
{
}
}
3 changes: 1 addition & 2 deletions Shuttle.Esb.Process.Tests/Shuttle.Esb.Process.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="Shuttle.Core.Container.Tests" Version="10.1.0" />
<PackageReference Include="Shuttle.Recall" Version="13.0.0" />
<PackageReference Include="Shuttle.Recall" Version="16.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Binary file removed Shuttle.Esb.Process/.build/Shuttle.MSBuild.dll
Binary file not shown.
11 changes: 0 additions & 11 deletions Shuttle.Esb.Process/.build/Shuttle.MSBuild.targets

This file was deleted.

68 changes: 0 additions & 68 deletions Shuttle.Esb.Process/.build/package.msbuild

This file was deleted.

27 changes: 0 additions & 27 deletions Shuttle.Esb.Process/.build/package.nuspec

This file was deleted.

22 changes: 22 additions & 0 deletions Shuttle.Esb.Process/.package/AssemblyInfo.cs.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Reflection;
using System.Runtime.InteropServices;

#if NETFRAMEWORK
[assembly: AssemblyTitle(".NET Framework")]
#endif

#if NETCOREAPP
[assembly: AssemblyTitle(".NET Core")]
#endif

#if NETSTANDARD
[assembly: AssemblyTitle(".NET Standard")]
#endif

[assembly: AssemblyVersion("#{SemanticVersionCore}#.0")]
[assembly: AssemblyCopyright("Copyright (c) #{Year}#, Eben Roux")]
[assembly: AssemblyProduct("Shuttle.Esb.Process")]
[assembly: AssemblyCompany("Eben Roux")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyInformationalVersion("#{SemanticVersion}#")]
[assembly: ComVisible(false)]
Binary file not shown.
12 changes: 12 additions & 0 deletions Shuttle.Esb.Process/.package/Shuttle.NuGetPackager.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PackageTasksPath Condition="'$(PackageTasksPath)' == ''">Shuttle.NuGetPackager.MSBuild.dll</PackageTasksPath>
</PropertyGroup>

<UsingTask AssemblyFile="$(PackageTasksPath)" TaskName="Shuttle.NuGetPackager.MSBuild.Prompt" />
<UsingTask AssemblyFile="$(PackageTasksPath)" TaskName="Shuttle.NuGetPackager.MSBuild.RegexFindAndReplace" />
<UsingTask AssemblyFile="$(PackageTasksPath)" TaskName="Shuttle.NuGetPackager.MSBuild.NuGet.SetNuGetPackageVersions" />
<UsingTask AssemblyFile="$(PackageTasksPath)" TaskName="Shuttle.NuGetPackager.MSBuild.Zip" />
<UsingTask AssemblyFile="$(PackageTasksPath)" TaskName="Shuttle.NuGetPackager.MSBuild.NuGet.SemanticVersion" />
</Project>
Loading

0 comments on commit 4e28ae2

Please sign in to comment.