Skip to content

Commit 700f272

Browse files
authored
Merge pull request #144 from buildersoftio/v2.0/release
V2.0/release
2 parents 475b75a + cf8b950 commit 700f272

38 files changed

Lines changed: 1669 additions & 78 deletions

Cortex.sln

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
Microsoft Visual Studio Solution File, Format Version 12.00
32
# Visual Studio Version 17
43
VisualStudioVersion = 17.10.34607.79
@@ -57,6 +56,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cortex.Streams.Elasticsearc
5756
EndProject
5857
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cortex.Types", "src\Cortex.Types\Cortex.Types.csproj", "{64E12D4C-FBB2-4004-8316-C886CBFC614B}"
5958
EndProject
59+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cortex.Vectors", "src\Cortex.Vectors\Cortex.Vectors.csproj", "{268BA5C7-C6FB-4A6B-875A-492659ED4573}"
60+
EndProject
61+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cortex.Mediator.Behaviors.FluentValidation", "src\Cortex.Mediator.Behaviors.FluentValidation\Cortex.Mediator.Behaviors.FluentValidation.csproj", "{44A166BD-01E9-4A4B-9BC5-7DE01B472E73}"
62+
EndProject
6063
Global
6164
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6265
Debug|Any CPU = Debug|Any CPU
@@ -170,6 +173,14 @@ Global
170173
{64E12D4C-FBB2-4004-8316-C886CBFC614B}.Debug|Any CPU.Build.0 = Debug|Any CPU
171174
{64E12D4C-FBB2-4004-8316-C886CBFC614B}.Release|Any CPU.ActiveCfg = Release|Any CPU
172175
{64E12D4C-FBB2-4004-8316-C886CBFC614B}.Release|Any CPU.Build.0 = Release|Any CPU
176+
{268BA5C7-C6FB-4A6B-875A-492659ED4573}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
177+
{268BA5C7-C6FB-4A6B-875A-492659ED4573}.Debug|Any CPU.Build.0 = Debug|Any CPU
178+
{268BA5C7-C6FB-4A6B-875A-492659ED4573}.Release|Any CPU.ActiveCfg = Release|Any CPU
179+
{268BA5C7-C6FB-4A6B-875A-492659ED4573}.Release|Any CPU.Build.0 = Release|Any CPU
180+
{44A166BD-01E9-4A4B-9BC5-7DE01B472E73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
181+
{44A166BD-01E9-4A4B-9BC5-7DE01B472E73}.Debug|Any CPU.Build.0 = Debug|Any CPU
182+
{44A166BD-01E9-4A4B-9BC5-7DE01B472E73}.Release|Any CPU.ActiveCfg = Release|Any CPU
183+
{44A166BD-01E9-4A4B-9BC5-7DE01B472E73}.Release|Any CPU.Build.0 = Release|Any CPU
173184
EndGlobalSection
174185
GlobalSection(SolutionProperties) = preSolution
175186
HideSolutionNode = FALSE

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
## Use Cases
2828

29+
2930
- Real-time analytics and monitoring
3031
- Event-driven architectures
3132
- Stateful stream processing (e.g., aggregations, joins)
@@ -122,6 +123,12 @@
122123
- **Cortex.Mediator:** implementation of the Mediator pattern for .NET applications, designed to power clean, modular architectures like **Vertical Slice Architecture** and **CQRS**.
123124
[![NuGet Version](https://img.shields.io/nuget/v/Cortex.Mediator?label=Cortex.Mediator)](https://www.nuget.org/packages/Cortex.Mediator)
124125

126+
- **Cortex.Mediator.Behaviors.FluentValidation:** implementation of the FluentValidation validation for Commands and Queries
127+
[![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)
128+
129+
- **Cortex.Vectors:** is a High‑performance vector types—Dense, Sparse, and Bit—for AI.
130+
[![NuGet Version](https://img.shields.io/nuget/v/Cortex.Vectors?label=Cortex.Vectors)](https://www.nuget.org/packages/Cortex.Vectors)
131+
125132

126133
## Getting Started
127134

62 KB
Loading
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2025 Buildersoft
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net9;net8;net7;netstandard2.1</TargetFrameworks>
5+
6+
<AssemblyVersion>1.0.0</AssemblyVersion>
7+
<FileVersion>1.0.0</FileVersion>
8+
<Product>Buildersoft Cortex Framework</Product>
9+
<Company>Buildersoft</Company>
10+
<LangVersion>12</LangVersion>
11+
<Authors>Buildersoft,EnesHoxha</Authors>
12+
<Copyright>Copyright © Buildersoft 2025</Copyright>
13+
14+
<Description>
15+
Buildersoft Cortex Mediator is a library for .NET applications that implements the mediator pattern. It helps to reduce dependencies between objects by allowing in-process messaging without direct communication. Instead, objects communicate through Cortex Mediator, making them less coupled and more maintainable..
16+
</Description>
17+
18+
19+
<RepositoryUrl>https://github.com/buildersoftio/cortex</RepositoryUrl>
20+
<PackageTags>cortex vortex mediator eda cqrs streaming</PackageTags>
21+
22+
<Version>1.0.0</Version>
23+
<PackageLicenseFile>license.md</PackageLicenseFile>
24+
<PackageIcon>andyX.png</PackageIcon>
25+
<PackageId>Cortex.Mediator.Behaviors.FluentValidation</PackageId>
26+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
27+
<IsPublishable>True</IsPublishable>
28+
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
29+
<RepositoryType></RepositoryType>
30+
<PackageReleaseNotes>Just as the Cortex in our brains handles complex processing efficiently, Cortex Data Framework brings brainpower to your data management! </PackageReleaseNotes>
31+
<PackageProjectUrl>https://buildersoft.io/</PackageProjectUrl>
32+
<Title>Cortex Mediator Behaviors FluentValidation</Title>
33+
<PackageReadmeFile>README.md</PackageReadmeFile>
34+
35+
</PropertyGroup>
36+
37+
<ItemGroup>
38+
<None Remove="README.md" />
39+
</ItemGroup>
40+
41+
<ItemGroup>
42+
<Content Include="README.md">
43+
<Pack>True</Pack>
44+
<PackagePath>\</PackagePath>
45+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
46+
</Content>
47+
</ItemGroup>
48+
<ItemGroup>
49+
<None Include="Assets\andyX.png">
50+
<Pack>True</Pack>
51+
<PackagePath></PackagePath>
52+
</None>
53+
<None Include="Assets\license.md">
54+
<Pack>True</Pack>
55+
<PackagePath></PackagePath>
56+
</None>
57+
</ItemGroup>
58+
59+
<ItemGroup>
60+
<Folder Include="Assets\" />
61+
</ItemGroup>
62+
63+
<ItemGroup>
64+
<ProjectReference Include="..\Cortex.Mediator\Cortex.Mediator.csproj" />
65+
</ItemGroup>
66+
67+
<ItemGroup>
68+
<PackageReference Include="FluentValidation" Version="11.11.0" />
69+
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.11.0" />
70+
</ItemGroup>
71+
72+
</Project>
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# Cortex.Mediator 🧠
2+
3+
**Cortex.Mediator** is a lightweight and extensible implementation of the Mediator pattern for .NET applications, designed to power clean, modular architectures like **Vertical Slice Architecture** and **CQRS**.
4+
5+
6+
Built as part of the [Cortex Data Framework](https://github.com/buildersoftio/cortex), this library simplifies command and query handling with built-in support for:
7+
8+
9+
- ✅ Commands & Queries
10+
- ✅ Notifications (Events)
11+
- ✅ Pipeline Behaviors
12+
- ✅ FluentValidation
13+
- ✅ Logging
14+
15+
---
16+
17+
[![GitHub License](https://img.shields.io/github/license/buildersoftio/cortex)](https://github.com/buildersoftio/cortex/blob/master/LICENSE)
18+
[![NuGet Version](https://img.shields.io/nuget/v/Cortex.Mediator?label=Cortex.Mediator)](https://www.nuget.org/packages/Cortex.Mediator)
19+
[![GitHub contributors](https://img.shields.io/github/contributors/buildersoftio/cortex)](https://github.com/buildersoftio/cortex)
20+
[![Discord Shield](https://discord.com/api/guilds/1310034212371566612/widget.png?style=shield)](https://discord.gg/JnMJV33QHu)
21+
22+
23+
## 🚀 Getting Started
24+
25+
### Install via NuGet
26+
27+
```bash
28+
dotnet add package Cortex.Mediator
29+
```
30+
31+
## 🛠️ Setup
32+
In `Program.cs` or `Startup.cs`:
33+
```csharp
34+
builder.Services.AddCortexMediator(
35+
builder.Configuration,
36+
new[] { typeof(Program) }, // Assemblies to scan for handlers
37+
options => options.AddDefaultBehaviors() // Logging
38+
);
39+
```
40+
41+
## 📦 Folder Structure Example (Vertical Slice)
42+
```bash
43+
Features/
44+
CreateUser/
45+
CreateUserCommand.cs
46+
CreateUserCommandHandler.cs
47+
CreateUserValidator.cs
48+
CreateUserEndpoint.cs
49+
```
50+
51+
## ✏️ Defining a Command
52+
53+
```csharp
54+
public class CreateUserCommand : ICommand<Guid>
55+
{
56+
public string UserName { get; set; }
57+
public string Email { get; set; }
58+
}
59+
```
60+
61+
### Handler
62+
```csharp
63+
public class CreateUserCommandHandler : ICommandHandler<CreateUserCommand,Guid>
64+
{
65+
public async Task<Guid> Handle(CreateUserCommand command, CancellationToken cancellationToken)
66+
{
67+
// Logic here
68+
}
69+
}
70+
```
71+
72+
### Validator (Optional, via FluentValidation) - Coming in the next release v1.8
73+
```csharp
74+
public class CreateUserValidator : AbstractValidator<CreateUserCommand>
75+
{
76+
public CreateUserValidator()
77+
{
78+
RuleFor(x => x.UserName).NotEmpty();
79+
RuleFor(x => x.Email).NotEmpty().EmailAddress();
80+
}
81+
}
82+
```
83+
84+
---
85+
86+
## 🔍 Defining a Query
87+
88+
```csharp
89+
public class GetUserQuery : IQuery<GetUserResponse>
90+
{
91+
public int UserId { get; set; }
92+
}
93+
```
94+
```csharp
95+
public class GetUserQueryHandler : IQueryHandler<GetUserQuery, GetUserResponse>
96+
{
97+
public async Task<GetUserResponse> Handle(GetUserQuery query, CancellationToken cancellationToken)
98+
{
99+
return new GetUserResponse { UserId = query.UserId, UserName = "Andy" };
100+
}
101+
}
102+
103+
```
104+
105+
## 📢 Notifications (Events)
106+
107+
```csharp
108+
public class UserCreatedNotification : INotification
109+
{
110+
public string UserName { get; set; }
111+
}
112+
113+
public class SendWelcomeEmailHandler : INotificationHandler<UserCreatedNotification>
114+
{
115+
public async Task Handle(UserCreatedNotification notification, CancellationToken cancellationToken)
116+
{
117+
// Send email...
118+
}
119+
}
120+
```
121+
```csharp
122+
await mediator.PublishAsync(new UserCreatedNotification { UserName = "Andy" });
123+
```
124+
125+
## 🔧 Pipeline Behaviors (Built-in)
126+
Out of the box, Cortex.Mediator supports:
127+
128+
- `ValidationCommandBehavior` - Coming in the next release v1.8
129+
- `LoggingCommandBehavior`
130+
131+
You can also register custom behaviors:
132+
```csharp
133+
options.AddOpenCommandPipelineBehavior(typeof(MyCustomBehavior<>));
134+
```
135+
136+
## 💬 Contributing
137+
We welcome contributions from the community! Whether it's reporting bugs, suggesting features, or submitting pull requests, your involvement helps improve Cortex for everyone.
138+
139+
### 💬 How to Contribute
140+
1. **Fork the Repository**
141+
2. **Create a Feature Branch**
142+
```bash
143+
git checkout -b feature/YourFeature
144+
```
145+
3. **Commit Your Changes**
146+
```bash
147+
git commit -m "Add your feature"
148+
```
149+
4. **Push to Your Fork**
150+
```bash
151+
git push origin feature/YourFeature
152+
```
153+
5. **Open a Pull Request**
154+
155+
Describe your changes and submit the pull request for review.
156+
157+
## 📄 License
158+
This project is licensed under the MIT License.
159+
160+
## 📚 Sponsorship
161+
Cortex is an open-source project maintained by BuilderSoft. Your support helps us continue developing and improving Cortex. Consider sponsoring us to contribute to the future of resilient streaming platforms.
162+
163+
### How to Sponsor
164+
* **Financial Contributions**: Support us through [GitHub Sponsors](https://github.com/sponsors/buildersoftio) or other preferred platforms.
165+
* **Corporate Sponsorship**: If your organization is interested in sponsoring Cortex, please contact us directly.
166+
167+
Contact Us: cortex@buildersoft.io
168+
169+
170+
## Contact
171+
We'd love to hear from you! Whether you have questions, feedback, or need support, feel free to reach out.
172+
173+
- Email: support@buildersoft.io
174+
- Website: https://buildersoft.io
175+
- GitHub Issues: [Cortex Data Framework Issues](https://github.com/buildersoftio/cortex/issues)
176+
- Join our Discord Community: [![Discord Shield](https://discord.com/api/guilds/1310034212371566612/widget.png?style=shield)](https://discord.gg/JnMJV33QHu)
177+
178+
179+
Thank you for using Cortex Data Framework! We hope it empowers you to build scalable and efficient data processing pipelines effortlessly.
180+
181+
Built with ❤️ by the Buildersoft team.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Cortex.Mediator.Commands;
2+
using FluentValidation;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
9+
namespace Cortex.Mediator.Behaviors
10+
{
11+
/// <summary>
12+
/// Pipeline behavior for validation command execution.
13+
/// </summary>
14+
public sealed class ValidationCommandBehavior<TCommand, TResult> : ICommandPipelineBehavior<TCommand, TResult>
15+
where TCommand : ICommand<TResult>
16+
{
17+
private readonly IEnumerable<IValidator<TCommand>> _validators;
18+
19+
20+
public async Task<TResult> Handle(TCommand command, CommandHandlerDelegate<TResult> next, CancellationToken cancellationToken)
21+
{
22+
var context = new ValidationContext<TCommand>(command);
23+
var failures = _validators
24+
.Select(v => v.Validate(context))
25+
.SelectMany(r => r.Errors)
26+
.Where(f => f != null)
27+
.ToList();
28+
29+
if (failures.Count() > 0)
30+
{
31+
var errors = failures
32+
.GroupBy(f => f.PropertyName)
33+
.ToDictionary(
34+
g => g.Key,
35+
g => g.Select(f => f.ErrorMessage).ToArray());
36+
37+
throw new Exceptions.ValidationException(errors);
38+
}
39+
40+
return await next();
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)