Skip to content

Commit 80cf202

Browse files
authored
Merge pull request #508 from Particular/support-new-saga-mapping
Support new saga mapping api
2 parents 9fd19c0 + 838e2ea commit 80cf202

26 files changed

+318
-32
lines changed

src/AcceptanceTestHelper/AcceptanceTestHelper.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@
1212
<ProjectReference Include="..\TestHelper\TestHelper.csproj" />
1313
</ItemGroup>
1414

15-
</Project>
15+
<ItemGroup>
16+
<PackageReference Include="NServiceBus" Version="[7.4.1,)" />
17+
</ItemGroup>
18+
19+
</Project>

src/AcceptanceTestHelper/ConfigureHowToFindSagaWithMessage.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Reflection;
44
using NServiceBus;
55

6-
class ConfigureHowToFindSagaWithMessage : IConfigureHowToFindSagaWithMessage
6+
class ConfigureHowToFindSagaWithMessage : IConfigureHowToFindSagaWithMessage, IConfigureHowToFindSagaWithMessageHeaders
77
{
88
public void ConfigureMapping<TSagaEntity, TMessage>(Expression<Func<TSagaEntity, object>> sagaEntityProperty, Expression<Func<TMessage, object>> messageProperty)
99
where TSagaEntity : IContainSagaData
@@ -15,6 +15,15 @@ public void ConfigureMapping<TSagaEntity, TMessage>(Expression<Func<TSagaEntity,
1515
CorrelationType = property.PropertyType;
1616
}
1717

18+
public void ConfigureMapping<TSagaEntity, TMessage>(Expression<Func<TSagaEntity, object>> sagaEntityProperty, string headerName) where TSagaEntity : IContainSagaData
19+
{
20+
var body = sagaEntityProperty.Body;
21+
var member = GetMemberExpression(body);
22+
var property = (PropertyInfo)member.Member;
23+
CorrelationProperty = property.Name;
24+
CorrelationType = property.PropertyType;
25+
}
26+
1827
MemberExpression GetMemberExpression(Expression body)
1928
{
2029
if (body is UnaryExpression unaryExpression)
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Reflection;
54
using NServiceBus;
65
using NServiceBus.Configuration.AdvancedExtensibility;
76

87
public static class EndpointConfigurationExtensions
98
{
10-
public static List<Type> ScannedTypes(this EndpointConfiguration configuration)
9+
public static List<Type> UserProvidedTypes(this EndpointConfiguration configuration)
1110
{
12-
var field = typeof(EndpointConfiguration)
13-
.GetField("ScannedTypes", BindingFlags.Instance | BindingFlags.NonPublic);
14-
if (field == null)
11+
var scannerConfigurationTypeName = "NServiceBus.AssemblyScanningComponent+Configuration";
12+
var userProvidedTypesPropertyName = "UserProvidedTypes";
13+
14+
var scannerConfiguration = configuration.GetSettings().Get(scannerConfigurationTypeName);
15+
16+
var property = scannerConfiguration.GetType().GetProperty(userProvidedTypesPropertyName);
17+
if (property == null)
1518
{
16-
throw new Exception("Could not extract field 'scannedTypes' from EndpointConfiguration.");
19+
throw new Exception($"Could not extract field '{userProvidedTypesPropertyName}' from {scannerConfigurationTypeName}.");
1720
}
18-
return (List<Type>)field.GetValue(configuration);
21+
return (List<Type>)property.GetValue(scannerConfiguration);
1922
}
2023

2124
public static bool IsSendOnly(this EndpointConfiguration configuration)
@@ -25,7 +28,7 @@ public static bool IsSendOnly(this EndpointConfiguration configuration)
2528

2629
public static IEnumerable<Type> GetScannedSagaTypes(this EndpointConfiguration configuration)
2730
{
28-
return configuration.ScannedTypes()
31+
return configuration.UserProvidedTypes()
2932
.Where(type => !type.IsAbstract && typeof(Saga).IsAssignableFrom(type));
3033
}
3134
}

src/AcceptanceTestsShared/When_different_persistence_is_for_outbox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ await Scenario.Define<Context>()
2121
.ConfigureAwait(false);
2222
});
2323

24-
StringAssert.StartsWith("Sagas and the Outbox need to use the same type of persistence.", ex.Message);
24+
StringAssert.StartsWith("Sql Persistence must be enabled for either both Sagas and Outbox, or neither.", ex.Message);
2525
}
2626

2727
public class Context : ScenarioContext

src/AcceptanceTestsShared/When_outbox_enabled_and_different_persistence_is_for_sagas.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ await Scenario.Define<Context>()
2121
.ConfigureAwait(false);
2222
});
2323

24-
StringAssert.StartsWith("Sagas and the Outbox need to use the same type of persistence.", ex.Message);
24+
StringAssert.StartsWith("Sql Persistence must be enabled for either both Sagas and Outbox, or neither.", ex.Message);
2525
}
2626

2727
public class Context : ScenarioContext

src/MsSqlMicrosoftDataClientAcceptanceTests/MsSqlMicrosoftDataClientAcceptanceTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
17-
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="7.2.4" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
17+
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="7.4.1" />
1818
<PackageReference Include="NUnit" Version="3.12.0" />
1919
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
2020
</ItemGroup>

src/MsSqlMicrosoftDataClientSqlTransportAcceptanceTests/MsSqlMicrosoftDataClientSqlTransportAcceptanceTests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
16-
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="7.2.4" GeneratePathProperty="true" />
17-
<PackageReference Include="NServiceBus.Transport.SqlServer" Version="6.0.1" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
16+
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="7.4.1" GeneratePathProperty="true" />
17+
<PackageReference Include="NServiceBus.Transport.SqlServer" Version="6.1.1" />
1818
<PackageReference Include="NUnit" Version="3.12.0" />
1919
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
2020
</ItemGroup>

src/MsSqlSystemDataClientAcceptanceTests/MsSqlSystemDataClientAcceptanceTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
17-
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="7.2.4" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
17+
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="7.4.1" />
1818
<PackageReference Include="NUnit" Version="3.12.0" />
1919
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
2020
</ItemGroup>

src/MsSqlSystemDataClientSqlTransportAcceptanceTests/MsSqlSystemDataClientSqlTransportAcceptanceTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
16-
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="7.2.4" GeneratePathProperty="true" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
16+
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="7.4.1" GeneratePathProperty="true" />
1717
<PackageReference Include="NServiceBus.SqlServer" Version="6.0.1" />
1818
<PackageReference Include="NUnit" Version="3.12.0" />
1919
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />

src/MySqlAcceptanceTests/ConfigureEndpointSqlPersistence.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public Task Configure(string endpointName, EndpointConfiguration configuration,
1414
{
1515
return Task.FromResult(0);
1616
}
17-
var tablePrefix = TableNameCleaner.Clean(endpointName).Substring(0, Math.Min(endpointName.Length, 35));
17+
var tablePrefix = TableNameCleaner.Clean(endpointName).Substring(0, Math.Min(endpointName.Length, 30));
1818
endpointHelper = new ConfigureEndpointHelper(configuration, tablePrefix, MySqlConnectionBuilder.Build, BuildSqlDialect.MySql);
1919
var persistence = configuration.UsePersistence<SqlPersistence>();
2020
persistence.ConnectionBuilder(MySqlConnectionBuilder.Build);

0 commit comments

Comments
 (0)