Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Snippets/TransactionalSession.CosmosDB/CosmosTS.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CosmosTS_1", "CosmosTS_1\Co
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CosmosTS_2", "CosmosTS_2\CosmosTS_2.csproj", "{0C3CBD7B-503C-4F25-9AFC-5DDE1BD70362}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CosmosTS_3", "CosmosTS_3\CosmosTS_3.csproj", "{503BB695-D7C9-439A-8E83-A3E5B3A56AA4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CosmosTS_4", "CosmosTS_4\CosmosTS_4.csproj", "{946086C4-7FF7-401A-B15D-43C828F6C212}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -40,6 +44,30 @@ Global
{0C3CBD7B-503C-4F25-9AFC-5DDE1BD70362}.Release|x64.Build.0 = Release|Any CPU
{0C3CBD7B-503C-4F25-9AFC-5DDE1BD70362}.Release|x86.ActiveCfg = Release|Any CPU
{0C3CBD7B-503C-4F25-9AFC-5DDE1BD70362}.Release|x86.Build.0 = Release|Any CPU
{503BB695-D7C9-439A-8E83-A3E5B3A56AA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{503BB695-D7C9-439A-8E83-A3E5B3A56AA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{503BB695-D7C9-439A-8E83-A3E5B3A56AA4}.Debug|x64.ActiveCfg = Debug|Any CPU
{503BB695-D7C9-439A-8E83-A3E5B3A56AA4}.Debug|x64.Build.0 = Debug|Any CPU
{503BB695-D7C9-439A-8E83-A3E5B3A56AA4}.Debug|x86.ActiveCfg = Debug|Any CPU
{503BB695-D7C9-439A-8E83-A3E5B3A56AA4}.Debug|x86.Build.0 = Debug|Any CPU
{503BB695-D7C9-439A-8E83-A3E5B3A56AA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{503BB695-D7C9-439A-8E83-A3E5B3A56AA4}.Release|Any CPU.Build.0 = Release|Any CPU
{503BB695-D7C9-439A-8E83-A3E5B3A56AA4}.Release|x64.ActiveCfg = Release|Any CPU
{503BB695-D7C9-439A-8E83-A3E5B3A56AA4}.Release|x64.Build.0 = Release|Any CPU
{503BB695-D7C9-439A-8E83-A3E5B3A56AA4}.Release|x86.ActiveCfg = Release|Any CPU
{503BB695-D7C9-439A-8E83-A3E5B3A56AA4}.Release|x86.Build.0 = Release|Any CPU
{946086C4-7FF7-401A-B15D-43C828F6C212}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{946086C4-7FF7-401A-B15D-43C828F6C212}.Debug|Any CPU.Build.0 = Debug|Any CPU
{946086C4-7FF7-401A-B15D-43C828F6C212}.Debug|x64.ActiveCfg = Debug|Any CPU
{946086C4-7FF7-401A-B15D-43C828F6C212}.Debug|x64.Build.0 = Debug|Any CPU
{946086C4-7FF7-401A-B15D-43C828F6C212}.Debug|x86.ActiveCfg = Debug|Any CPU
{946086C4-7FF7-401A-B15D-43C828F6C212}.Debug|x86.Build.0 = Debug|Any CPU
{946086C4-7FF7-401A-B15D-43C828F6C212}.Release|Any CPU.ActiveCfg = Release|Any CPU
{946086C4-7FF7-401A-B15D-43C828F6C212}.Release|Any CPU.Build.0 = Release|Any CPU
{946086C4-7FF7-401A-B15D-43C828F6C212}.Release|x64.ActiveCfg = Release|Any CPU
{946086C4-7FF7-401A-B15D-43C828F6C212}.Release|x64.Build.0 = Release|Any CPU
{946086C4-7FF7-401A-B15D-43C828F6C212}.Release|x86.ActiveCfg = Release|Any CPU
{946086C4-7FF7-401A-B15D-43C828F6C212}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Microsoft.Extensions.DependencyInjection;
using NServiceBus;
using NServiceBus.TransactionalSession;
using System;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;

public class CosmosDBConfig
{
public void Configure(EndpointConfiguration config)
{
#region enabling-transactional-session-cosmos

var persistence = config.UsePersistence<CosmosPersistence>();
persistence.EnableTransactionalSession();

#endregion
}

private async Task OpenDefault(IServiceProvider serviceProvider)
{
#region open-transactional-session-cosmos

using var childScope = serviceProvider.CreateScope();
var session = childScope.ServiceProvider.GetService<ITransactionalSession>();
await session.Open(
new CosmosOpenSessionOptions(
new PartitionKey("MyPartitionKey")));

// use the session

await session.Commit();

#endregion
}

public async Task OpenContainerInfo(IServiceProvider serviceProvider)
{
#region open-transactional-session-cosmos-container

using var childScope = serviceProvider.CreateScope();
var session = childScope.ServiceProvider.GetService<ITransactionalSession>();
await session.Open(
new CosmosOpenSessionOptions(
new PartitionKey("MyPartitionKey"),
new ContainerInformation(
"MyContainer",
new PartitionKeyPath("/path/to/partition/key"))));

// use the session

await session.Commit();

#endregion
}

public async Task UseSession(ITransactionalSession session)
{
#region use-transactional-session-cosmos
await session.Open(
new CosmosOpenSessionOptions(
new PartitionKey("MyPartitionKey")));

// add messages to the transaction:
await session.Send(new MyMessage());

// access the database:
var cosmosSession = session.SynchronizedStorageSession.CosmosPersistenceSession();

await session.Commit();
#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NServiceBus.Persistence.CosmosDB.TransactionalSession" Version="3.*" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using NServiceBus;

public class MyMessage : ICommand
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Microsoft.Extensions.DependencyInjection;
using NServiceBus;
using NServiceBus.TransactionalSession;
using System;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;

public class CosmosDBConfig
{
public void Configure(EndpointConfiguration config)
{
#region enabling-transactional-session-cosmos

var persistence = config.UsePersistence<CosmosPersistence>();
persistence.EnableTransactionalSession();

#endregion
}

private async Task OpenDefault(IServiceProvider serviceProvider)
{
#region open-transactional-session-cosmos

using var childScope = serviceProvider.CreateScope();
var session = childScope.ServiceProvider.GetService<ITransactionalSession>();
await session.Open(
new CosmosOpenSessionOptions(
new PartitionKey("MyPartitionKey")));

// use the session

await session.Commit();

#endregion
}

public async Task OpenContainerInfo(IServiceProvider serviceProvider)
{
#region open-transactional-session-cosmos-container

using var childScope = serviceProvider.CreateScope();
var session = childScope.ServiceProvider.GetService<ITransactionalSession>();
await session.Open(
new CosmosOpenSessionOptions(
new PartitionKey("MyPartitionKey"),
new ContainerInformation(
"MyContainer",
new PartitionKeyPath("/path/to/partition/key"))));

// use the session

await session.Commit();

#endregion
}

public async Task UseSession(ITransactionalSession session)
{
#region use-transactional-session-cosmos
await session.Open(
new CosmosOpenSessionOptions(
new PartitionKey("MyPartitionKey")));

// add messages to the transaction:
await session.Send(new MyMessage());

// access the database:
var cosmosSession = session.SynchronizedStorageSession.CosmosPersistenceSession();

await session.Commit();
#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NServiceBus.Persistence.CosmosDB.TransactionalSession" Version="4.0.0-alpha.2" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using NServiceBus;

public class MyMessage : ICommand
{
}
Empty file.
Loading