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
7 changes: 7 additions & 0 deletions Cortex.sln
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cortex.Streams.Mediator", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cortex.States.DuckDb", "src\Cortex.States.DuckDb\Cortex.States.DuckDb.csproj", "{4FAE6C5E-53EE-4CCE-85A6-B7551A92C488}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cortex.Mediator.Behaviors.Transactional", "src\Cortex.Mediator.Behaviors.Transactional\Cortex.Mediator.Behaviors.Transactional.csproj", "{F7C9F778-EFDB-4F02-8F19-43A9F4A86003}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -208,6 +210,10 @@ Global
{4FAE6C5E-53EE-4CCE-85A6-B7551A92C488}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FAE6C5E-53EE-4CCE-85A6-B7551A92C488}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FAE6C5E-53EE-4CCE-85A6-B7551A92C488}.Release|Any CPU.Build.0 = Release|Any CPU
{F7C9F778-EFDB-4F02-8F19-43A9F4A86003}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7C9F778-EFDB-4F02-8F19-43A9F4A86003}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7C9F778-EFDB-4F02-8F19-43A9F4A86003}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7C9F778-EFDB-4F02-8F19-43A9F4A86003}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -240,6 +246,7 @@ Global
{472BC645-9E2F-4205-A571-4D9184747EC5} = {7F9E0AEA-721E-46F8-90ED-8EA8423647FB}
{84410C57-0F59-F31F-B921-4C1F3D3FF144} = {4C68702C-1661-4AD9-83FD-E0B52B791969}
{4FAE6C5E-53EE-4CCE-85A6-B7551A92C488} = {C31F8C0F-8BCF-4959-9BA1-8645D058EAA0}
{F7C9F778-EFDB-4F02-8F19-43A9F4A86003} = {1C5D462D-168D-4D3F-B96E-CCE5517DB197}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E20303B6-8AC9-4FFF-B645-4608309ADA94}
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
- **Cortex.Mediator.Behaviors.FluentValidation:** implementation of the FluentValidation validation for Commands and Queries
[![NuGet Version](https://img.shields.io/nuget/v/Cortex.Mediator.Behaviors.FluentValidation?label=Cortex.Mediator.Behaviors.FluentValidation)](https://www.nuget.org/packages/Cortex.Mediator.Behaviors.FluentValidation)

- **Cortex.Mediator.Behaviors.Transactional:** implementation of the Transactional Behaviors for Commands
[![NuGet Version](https://img.shields.io/nuget/v/Cortex.Mediator.Behaviors.Transactional?label=Cortex.Mediator.Behaviors.Transactional)](https://www.nuget.org/packages/Cortex.Mediator.Behaviors.Transactional)

- **Cortex.Vectors:** is a High‑performance vector types—Dense, Sparse, and Bit—for AI.
[![NuGet Version](https://img.shields.io/nuget/v/Cortex.Vectors?label=Cortex.Vectors)](https://www.nuget.org/packages/Cortex.Vectors)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2025 Buildersoft
Copyright (c) 2026 Buildersoft

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions src/Cortex.Mediator.Behaviors.Transactional/Assets/license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2026 Buildersoft

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>

<AssemblyVersion>3.0.0</AssemblyVersion>
<FileVersion>3.0.0</FileVersion>
<Product>Buildersoft Cortex Framework</Product>
<Company>Buildersoft</Company>
<LangVersion>12</LangVersion>
<Authors>Buildersoft,EnesHoxha</Authors>
<Copyright>Copyright © Buildersoft 2025</Copyright>

<Description>
Cortex.Mediator.Behaviors.Transactional provides transactional pipeline behaviors for Cortex.Mediator.
Wrap command execution in TransactionScope for automatic commit on success and rollback on failure.
Supports custom transaction contexts for Entity Framework, Dapper, and other ORM integrations.
</Description>

<RepositoryUrl>https://github.com/buildersoftio/cortex</RepositoryUrl>
<PackageTags>cortex mediator transactions transactional cqrs pipeline behavior</PackageTags>

<Version>3.0.0</Version>
<PackageLicenseFile>license.md</PackageLicenseFile>
<PackageIcon>cortex.png</PackageIcon>
<PackageId>Cortex.Mediator.Behaviors.Transactional</PackageId>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<IsPublishable>True</IsPublishable>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<RepositoryType></RepositoryType>
<PackageReleaseNotes>Initial release of Cortex.Mediator.Behaviors.Transactional - Provides transactional pipeline behaviors for atomic command execution.</PackageReleaseNotes>
<PackageProjectUrl>https://buildersoft.io/</PackageProjectUrl>
<Title>Cortex Mediator Behaviors Transactional</Title>
<PackageReadmeFile>README.md</PackageReadmeFile>

</PropertyGroup>

<ItemGroup>
<None Remove="README.md" />
</ItemGroup>

<ItemGroup>
<Content Include="README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<None Include="Assets\cortex.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
<None Include="Assets\license.md">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<Folder Include="Assets\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Cortex.Mediator\Cortex.Mediator.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Cortex.Mediator.DependencyInjection;

namespace Cortex.Mediator.Behaviors.Transactional.DependencyInjection
{
/// <summary>
/// Extension methods for adding transactional behaviors to the mediator options.
/// </summary>
public static class MediatorOptionsExtensions
{
/// <summary>
/// Adds transactional pipeline behaviors for commands.
/// This will wrap command execution in a transaction scope.
/// </summary>
/// <param name="options">The mediator options.</param>
/// <returns>The mediator options for chaining.</returns>
public static MediatorOptions AddTransactionalBehaviors(this MediatorOptions options)
{
options.AddOpenCommandPipelineBehavior(typeof(TransactionalCommandBehavior<,>))
.AddOpenCommandPipelineBehavior(typeof(TransactionalCommandBehavior<>));

return options;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;

namespace Cortex.Mediator.Behaviors.Transactional.DependencyInjection
{
/// <summary>
/// Extension methods for configuring transactional services in the dependency injection container.
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds transactional behavior support to the service collection with default options.
/// </summary>
/// <param name="services">The service collection.</param>
/// <returns>The service collection for chaining.</returns>
public static IServiceCollection AddTransactionalBehavior(this IServiceCollection services)
{
return services.AddTransactionalBehavior(options => { });
}

/// <summary>
/// Adds transactional behavior support to the service collection with custom options.
/// </summary>
/// <param name="services">The service collection.</param>
/// <param name="configureOptions">Action to configure the transactional options.</param>
/// <returns>The service collection for chaining.</returns>
public static IServiceCollection AddTransactionalBehavior(
this IServiceCollection services,
Action<TransactionalOptions> configureOptions)
{
var options = new TransactionalOptions();
configureOptions?.Invoke(options);

services.TryAddSingleton(options);

return services;
}

/// <summary>
/// Adds a custom transactional context implementation to the service collection.
/// </summary>
/// <typeparam name="TContext">The type of transactional context.</typeparam>
/// <param name="services">The service collection.</param>
/// <returns>The service collection for chaining.</returns>
public static IServiceCollection AddTransactionalContext<TContext>(this IServiceCollection services)
where TContext : class, ITransactionalContext
{
services.TryAddScoped<ITransactionalContext, TContext>();
return services;
}

/// <summary>
/// Adds a custom transactional context implementation to the service collection with a factory.
/// </summary>
/// <typeparam name="TContext">The type of transactional context.</typeparam>
/// <param name="services">The service collection.</param>
/// <param name="implementationFactory">The factory that creates the context.</param>
/// <returns>The service collection for chaining.</returns>
public static IServiceCollection AddTransactionalContext<TContext>(
this IServiceCollection services,
Func<IServiceProvider, TContext> implementationFactory)
where TContext : class, ITransactionalContext
{
services.TryAddScoped<ITransactionalContext>(implementationFactory);
return services;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Threading;
using System.Threading.Tasks;

namespace Cortex.Mediator.Behaviors.Transactional
{
/// <summary>
/// Defines a contract for custom transaction management.
/// Implement this interface to provide custom transaction handling (e.g., Entity Framework, Dapper, etc.).
/// </summary>
public interface ITransactionalContext
{
/// <summary>
/// Begins a new transaction asynchronously.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task representing the asynchronous operation.</returns>
Task BeginTransactionAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Commits the current transaction asynchronously.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task representing the asynchronous operation.</returns>
Task CommitAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Rolls back the current transaction asynchronously.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task representing the asynchronous operation.</returns>
Task RollbackAsync(CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace Cortex.Mediator.Behaviors.Transactional
{
/// <summary>
/// Attribute to mark commands that should be excluded from transactional behavior.
/// Commands decorated with this attribute will execute without a transaction wrapper.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class NonTransactionalAttribute : Attribute
{
}
}
Loading