Skip to content

Commit a043a0c

Browse files
authored
Add NServiceBus 10 version of the Transactional session RavenDB snippets (#7778)
* Add snippets for the previously released versions * Add NServiceBus 10 version of the Transactional session RavenDB snippets
1 parent dd91825 commit a043a0c

File tree

11 files changed

+291
-0
lines changed

11 files changed

+291
-0
lines changed

Snippets/TransactionalSession.RavenDB/RavenTS.sln

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RavenTS_7", "RavenTS_7\Rave
66
EndProject
77
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RavenTS_8", "RavenTS_8\RavenTS_8.csproj", "{241C38E1-DEB6-4BE9-98CE-C9AEAE0D8D8D}"
88
EndProject
9+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RavenTS_9", "RavenTS_9\RavenTS_9.csproj", "{3FDD052B-BD1C-4791-AA43-FDCCCF74000C}"
10+
EndProject
11+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RavenTS_10", "RavenTS_10\RavenTS_10.csproj", "{8FA4521F-7C25-4AE2-8231-705C2D362B54}"
12+
EndProject
13+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RavenTS_11", "RavenTS_11\RavenTS_11.csproj", "{C6A42B2B-DE09-4459-B1B3-4FC168004CEC}"
14+
EndProject
915
Global
1016
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1117
Debug|Any CPU = Debug|Any CPU
@@ -40,6 +46,42 @@ Global
4046
{241C38E1-DEB6-4BE9-98CE-C9AEAE0D8D8D}.Release|x64.Build.0 = Release|Any CPU
4147
{241C38E1-DEB6-4BE9-98CE-C9AEAE0D8D8D}.Release|x86.ActiveCfg = Release|Any CPU
4248
{241C38E1-DEB6-4BE9-98CE-C9AEAE0D8D8D}.Release|x86.Build.0 = Release|Any CPU
49+
{3FDD052B-BD1C-4791-AA43-FDCCCF74000C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50+
{3FDD052B-BD1C-4791-AA43-FDCCCF74000C}.Debug|Any CPU.Build.0 = Debug|Any CPU
51+
{3FDD052B-BD1C-4791-AA43-FDCCCF74000C}.Debug|x64.ActiveCfg = Debug|Any CPU
52+
{3FDD052B-BD1C-4791-AA43-FDCCCF74000C}.Debug|x64.Build.0 = Debug|Any CPU
53+
{3FDD052B-BD1C-4791-AA43-FDCCCF74000C}.Debug|x86.ActiveCfg = Debug|Any CPU
54+
{3FDD052B-BD1C-4791-AA43-FDCCCF74000C}.Debug|x86.Build.0 = Debug|Any CPU
55+
{3FDD052B-BD1C-4791-AA43-FDCCCF74000C}.Release|Any CPU.ActiveCfg = Release|Any CPU
56+
{3FDD052B-BD1C-4791-AA43-FDCCCF74000C}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{3FDD052B-BD1C-4791-AA43-FDCCCF74000C}.Release|x64.ActiveCfg = Release|Any CPU
58+
{3FDD052B-BD1C-4791-AA43-FDCCCF74000C}.Release|x64.Build.0 = Release|Any CPU
59+
{3FDD052B-BD1C-4791-AA43-FDCCCF74000C}.Release|x86.ActiveCfg = Release|Any CPU
60+
{3FDD052B-BD1C-4791-AA43-FDCCCF74000C}.Release|x86.Build.0 = Release|Any CPU
61+
{8FA4521F-7C25-4AE2-8231-705C2D362B54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
62+
{8FA4521F-7C25-4AE2-8231-705C2D362B54}.Debug|Any CPU.Build.0 = Debug|Any CPU
63+
{8FA4521F-7C25-4AE2-8231-705C2D362B54}.Debug|x64.ActiveCfg = Debug|Any CPU
64+
{8FA4521F-7C25-4AE2-8231-705C2D362B54}.Debug|x64.Build.0 = Debug|Any CPU
65+
{8FA4521F-7C25-4AE2-8231-705C2D362B54}.Debug|x86.ActiveCfg = Debug|Any CPU
66+
{8FA4521F-7C25-4AE2-8231-705C2D362B54}.Debug|x86.Build.0 = Debug|Any CPU
67+
{8FA4521F-7C25-4AE2-8231-705C2D362B54}.Release|Any CPU.ActiveCfg = Release|Any CPU
68+
{8FA4521F-7C25-4AE2-8231-705C2D362B54}.Release|Any CPU.Build.0 = Release|Any CPU
69+
{8FA4521F-7C25-4AE2-8231-705C2D362B54}.Release|x64.ActiveCfg = Release|Any CPU
70+
{8FA4521F-7C25-4AE2-8231-705C2D362B54}.Release|x64.Build.0 = Release|Any CPU
71+
{8FA4521F-7C25-4AE2-8231-705C2D362B54}.Release|x86.ActiveCfg = Release|Any CPU
72+
{8FA4521F-7C25-4AE2-8231-705C2D362B54}.Release|x86.Build.0 = Release|Any CPU
73+
{C6A42B2B-DE09-4459-B1B3-4FC168004CEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
74+
{C6A42B2B-DE09-4459-B1B3-4FC168004CEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
75+
{C6A42B2B-DE09-4459-B1B3-4FC168004CEC}.Debug|x64.ActiveCfg = Debug|Any CPU
76+
{C6A42B2B-DE09-4459-B1B3-4FC168004CEC}.Debug|x64.Build.0 = Debug|Any CPU
77+
{C6A42B2B-DE09-4459-B1B3-4FC168004CEC}.Debug|x86.ActiveCfg = Debug|Any CPU
78+
{C6A42B2B-DE09-4459-B1B3-4FC168004CEC}.Debug|x86.Build.0 = Debug|Any CPU
79+
{C6A42B2B-DE09-4459-B1B3-4FC168004CEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
80+
{C6A42B2B-DE09-4459-B1B3-4FC168004CEC}.Release|Any CPU.Build.0 = Release|Any CPU
81+
{C6A42B2B-DE09-4459-B1B3-4FC168004CEC}.Release|x64.ActiveCfg = Release|Any CPU
82+
{C6A42B2B-DE09-4459-B1B3-4FC168004CEC}.Release|x64.Build.0 = Release|Any CPU
83+
{C6A42B2B-DE09-4459-B1B3-4FC168004CEC}.Release|x86.ActiveCfg = Release|Any CPU
84+
{C6A42B2B-DE09-4459-B1B3-4FC168004CEC}.Release|x86.Build.0 = Release|Any CPU
4385
EndGlobalSection
4486
GlobalSection(SolutionProperties) = preSolution
4587
HideSolutionNode = FALSE
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using NServiceBus;
2+
3+
public class MyMessage : ICommand
4+
{
5+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using NServiceBus;
3+
using NServiceBus.TransactionalSession;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Threading.Tasks;
7+
8+
public class RavenDBConfig
9+
{
10+
public void Configure(EndpointConfiguration config)
11+
{
12+
#region enabling-transactional-session-ravendb
13+
14+
var persistence = config.UsePersistence<RavenDBPersistence>();
15+
persistence.EnableTransactionalSession();
16+
17+
#endregion
18+
}
19+
20+
private async Task OpenDefault(IServiceProvider serviceProvider)
21+
{
22+
#region open-transactional-session-ravendb
23+
24+
using var childScope = serviceProvider.CreateScope();
25+
var session = childScope.ServiceProvider.GetService<ITransactionalSession>();
26+
await session.Open(new RavenDbOpenSessionOptions());
27+
28+
// use the session
29+
30+
await session.Commit();
31+
32+
#endregion
33+
}
34+
35+
public async Task OpenMultiTenant(IServiceProvider serviceProvider)
36+
{
37+
#region open-transactional-session-ravendb-multitenant
38+
39+
using var childScope = serviceProvider.CreateScope();
40+
var session = childScope.ServiceProvider.GetService<ITransactionalSession>();
41+
await session.Open(
42+
new RavenDbOpenSessionOptions(
43+
new Dictionary<string, string>
44+
{
45+
// information is added to the message headers for the `SetMessageToDatabaseMappingConvention`-method
46+
{"tenantDatabaseName", "tenantA-databaseName"}
47+
}));
48+
49+
// use the session
50+
51+
await session.Commit();
52+
53+
#endregion
54+
}
55+
56+
public async Task UseSession(ITransactionalSession session)
57+
{
58+
#region use-transactional-session-raven
59+
await session.Open(new RavenDbOpenSessionOptions());
60+
61+
// add messages to the transaction:
62+
await session.Send(new MyMessage());
63+
64+
// access the database:
65+
var ravenSession = session.SynchronizedStorageSession.RavenSession();
66+
67+
await session.Commit();
68+
#endregion
69+
}
70+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<PackageReference Include="NServiceBus.RavenDB.TransactionalSession" Version="10.*" />
7+
</ItemGroup>
8+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using NServiceBus;
2+
3+
public class MyMessage : ICommand
4+
{
5+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using NServiceBus;
3+
using NServiceBus.TransactionalSession;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Threading.Tasks;
7+
8+
public class RavenDBConfig
9+
{
10+
public void Configure(EndpointConfiguration config)
11+
{
12+
#region enabling-transactional-session-ravendb
13+
14+
var persistence = config.UsePersistence<RavenDBPersistence>();
15+
persistence.EnableTransactionalSession();
16+
17+
#endregion
18+
}
19+
20+
private async Task OpenDefault(IServiceProvider serviceProvider)
21+
{
22+
#region open-transactional-session-ravendb
23+
24+
using var childScope = serviceProvider.CreateScope();
25+
var session = childScope.ServiceProvider.GetService<ITransactionalSession>();
26+
await session.Open(new RavenDbOpenSessionOptions());
27+
28+
// use the session
29+
30+
await session.Commit();
31+
32+
#endregion
33+
}
34+
35+
public async Task OpenMultiTenant(IServiceProvider serviceProvider)
36+
{
37+
#region open-transactional-session-ravendb-multitenant
38+
39+
using var childScope = serviceProvider.CreateScope();
40+
var session = childScope.ServiceProvider.GetService<ITransactionalSession>();
41+
await session.Open(
42+
new RavenDbOpenSessionOptions(
43+
new Dictionary<string, string>
44+
{
45+
// information is added to the message headers for the `SetMessageToDatabaseMappingConvention`-method
46+
{"tenantDatabaseName", "tenantA-databaseName"}
47+
}));
48+
49+
// use the session
50+
51+
await session.Commit();
52+
53+
#endregion
54+
}
55+
56+
public async Task UseSession(ITransactionalSession session)
57+
{
58+
#region use-transactional-session-raven
59+
await session.Open(new RavenDbOpenSessionOptions());
60+
61+
// add messages to the transaction:
62+
await session.Send(new MyMessage());
63+
64+
// access the database:
65+
var ravenSession = session.SynchronizedStorageSession.RavenSession();
66+
67+
await session.Commit();
68+
#endregion
69+
}
70+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net10.0</TargetFramework>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<PackageReference Include="NServiceBus.RavenDB.TransactionalSession" Version="11.0.0-alpha.1" />
7+
</ItemGroup>
8+
</Project>

Snippets/TransactionalSession.RavenDB/RavenTS_11/prerelease.txt

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using NServiceBus;
2+
3+
public class MyMessage : ICommand
4+
{
5+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using NServiceBus;
3+
using NServiceBus.TransactionalSession;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Threading.Tasks;
7+
8+
public class RavenDBConfig
9+
{
10+
public void Configure(EndpointConfiguration config)
11+
{
12+
#region enabling-transactional-session-ravendb
13+
14+
var persistence = config.UsePersistence<RavenDBPersistence>();
15+
persistence.EnableTransactionalSession();
16+
17+
#endregion
18+
}
19+
20+
private async Task OpenDefault(IServiceProvider serviceProvider)
21+
{
22+
#region open-transactional-session-ravendb
23+
24+
using var childScope = serviceProvider.CreateScope();
25+
var session = childScope.ServiceProvider.GetService<ITransactionalSession>();
26+
await session.Open(new RavenDbOpenSessionOptions());
27+
28+
// use the session
29+
30+
await session.Commit();
31+
32+
#endregion
33+
}
34+
35+
public async Task OpenMultiTenant(IServiceProvider serviceProvider)
36+
{
37+
#region open-transactional-session-ravendb-multitenant
38+
39+
using var childScope = serviceProvider.CreateScope();
40+
var session = childScope.ServiceProvider.GetService<ITransactionalSession>();
41+
await session.Open(
42+
new RavenDbOpenSessionOptions(
43+
new Dictionary<string, string>
44+
{
45+
// information is added to the message headers for the `SetMessageToDatabaseMappingConvention`-method
46+
{"tenantDatabaseName", "tenantA-databaseName"}
47+
}));
48+
49+
// use the session
50+
51+
await session.Commit();
52+
53+
#endregion
54+
}
55+
56+
public async Task UseSession(ITransactionalSession session)
57+
{
58+
#region use-transactional-session-raven
59+
await session.Open(new RavenDbOpenSessionOptions());
60+
61+
// add messages to the transaction:
62+
await session.Send(new MyMessage());
63+
64+
// access the database:
65+
var ravenSession = session.SynchronizedStorageSession.RavenSession();
66+
67+
await session.Commit();
68+
#endregion
69+
}
70+
}

0 commit comments

Comments
 (0)