Skip to content

Commit b9cf456

Browse files
authored
Merge pull request #167 from buildersoftio/v2.2/release
V2.2/release
2 parents 700f272 + 65f6d40 commit b9cf456

45 files changed

Lines changed: 2611 additions & 19 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cortex.sln

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio Version 17
3-
VisualStudioVersion = 17.10.34607.79
2+
# Visual Studio Version 18
3+
VisualStudioVersion = 18.0.11111.16
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cortex.Mediator", "src\Cortex.Mediator\Cortex.Mediator.csproj", "{F1CC775A-95DA-4A5A-879F-66BFCB0FDCC9}"
66
EndProject
@@ -60,6 +60,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cortex.Vectors", "src\Corte
6060
EndProject
6161
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}"
6262
EndProject
63+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cortex.Serialization.Yaml", "src\Cortex.Serialization.Yaml\Cortex.Serialization.Yaml.csproj", "{472BC645-9E2F-4205-A571-4D9184747EC5}"
64+
EndProject
65+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Mediator", "Mediator", "{1C5D462D-168D-4D3F-B96E-CCE5517DB197}"
66+
EndProject
67+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Streams", "Streams", "{4C68702C-1661-4AD9-83FD-E0B52B791969}"
68+
EndProject
69+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "States", "States", "{C31F8C0F-8BCF-4959-9BA1-8645D058EAA0}"
70+
EndProject
71+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Serialization", "Serialization", "{7F9E0AEA-721E-46F8-90ED-8EA8423647FB}"
72+
EndProject
6373
Global
6474
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6575
Debug|Any CPU = Debug|Any CPU
@@ -119,6 +129,7 @@ Global
119129
{D51C6B82-ABD9-4C43-820E-237EDBD706A1}.Release|Any CPU.ActiveCfg = Release|AnyCPU
120130
{D51C6B82-ABD9-4C43-820E-237EDBD706A1}.Release|Any CPU.Build.0 = Release|AnyCPU
121131
{C9A7699A-9BCF-4B51-B29F-ABF78DCEA553}.Debug|Any CPU.ActiveCfg = Debug|AnyCPU
132+
{C9A7699A-9BCF-4B51-B29F-ABF78DCEA553}.Debug|Any CPU.Build.0 = Debug|AnyCPU
122133
{C9A7699A-9BCF-4B51-B29F-ABF78DCEA553}.Release|Any CPU.ActiveCfg = Release|AnyCPU
123134
{C9A7699A-9BCF-4B51-B29F-ABF78DCEA553}.Release|Any CPU.Build.0 = Release|AnyCPU
124135
{D376D6CA-3192-4EDC-B840-31F58B6457DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -181,10 +192,41 @@ Global
181192
{44A166BD-01E9-4A4B-9BC5-7DE01B472E73}.Debug|Any CPU.Build.0 = Debug|Any CPU
182193
{44A166BD-01E9-4A4B-9BC5-7DE01B472E73}.Release|Any CPU.ActiveCfg = Release|Any CPU
183194
{44A166BD-01E9-4A4B-9BC5-7DE01B472E73}.Release|Any CPU.Build.0 = Release|Any CPU
195+
{472BC645-9E2F-4205-A571-4D9184747EC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
196+
{472BC645-9E2F-4205-A571-4D9184747EC5}.Debug|Any CPU.Build.0 = Debug|Any CPU
197+
{472BC645-9E2F-4205-A571-4D9184747EC5}.Release|Any CPU.ActiveCfg = Release|Any CPU
198+
{472BC645-9E2F-4205-A571-4D9184747EC5}.Release|Any CPU.Build.0 = Release|Any CPU
184199
EndGlobalSection
185200
GlobalSection(SolutionProperties) = preSolution
186201
HideSolutionNode = FALSE
187202
EndGlobalSection
203+
GlobalSection(NestedProjects) = preSolution
204+
{F1CC775A-95DA-4A5A-879F-66BFCB0FDCC9} = {1C5D462D-168D-4D3F-B96E-CCE5517DB197}
205+
{1C8605F4-91CB-49A4-A080-0A6DFE1FB010} = {4C68702C-1661-4AD9-83FD-E0B52B791969}
206+
{96701658-663E-41C5-9EF9-843C79CE727A} = {4C68702C-1661-4AD9-83FD-E0B52B791969}
207+
{EE799E10-7469-428E-AF8C-F2807F6CE7E5} = {4C68702C-1661-4AD9-83FD-E0B52B791969}
208+
{34CA231A-1E3A-4CA4-820C-946DC8E2737F} = {C31F8C0F-8BCF-4959-9BA1-8645D058EAA0}
209+
{16FA00B1-973B-443C-BF84-9B76DCAF341B} = {C31F8C0F-8BCF-4959-9BA1-8645D058EAA0}
210+
{1F60F66A-5DC0-4C1D-A7B7-66F568A26911} = {4C68702C-1661-4AD9-83FD-E0B52B791969}
211+
{2B949637-FC31-4F51-A391-19F76B57CC28} = {4C68702C-1661-4AD9-83FD-E0B52B791969}
212+
{6E5AC0AC-A364-4DB3-9E9A-C2FB54BD6D1E} = {4C68702C-1661-4AD9-83FD-E0B52B791969}
213+
{6019F9E6-C377-416D-9E3B-3D7104FAEB63} = {4C68702C-1661-4AD9-83FD-E0B52B791969}
214+
{20FAE1F1-D677-4E0E-B3A7-E2B1485C874C} = {4C68702C-1661-4AD9-83FD-E0B52B791969}
215+
{D376D6CA-3192-4EDC-B840-31F58B6457DD} = {4C68702C-1661-4AD9-83FD-E0B52B791969}
216+
{447970B9-C5AA-41D9-A07F-330A251597D0} = {C31F8C0F-8BCF-4959-9BA1-8645D058EAA0}
217+
{00358701-D117-4953-A673-D60625D38466} = {C31F8C0F-8BCF-4959-9BA1-8645D058EAA0}
218+
{77AD462F-A248-43AF-9212-43031F22F23D} = {C31F8C0F-8BCF-4959-9BA1-8645D058EAA0}
219+
{980EDBFE-40C2-4EFD-96C2-FED1032FB5E6} = {C31F8C0F-8BCF-4959-9BA1-8645D058EAA0}
220+
{0F9FCB99-D00F-4396-8E2B-6E627076ADA0} = {C31F8C0F-8BCF-4959-9BA1-8645D058EAA0}
221+
{20BD7107-8199-4CA8-815B-4D156B522B82} = {4C68702C-1661-4AD9-83FD-E0B52B791969}
222+
{19167D25-6383-46B4-9449-B9E364F809FF} = {C31F8C0F-8BCF-4959-9BA1-8645D058EAA0}
223+
{81A01446-A8AA-4F9D-BB9B-B66E21B2C348} = {4C68702C-1661-4AD9-83FD-E0B52B791969}
224+
{0E60F75D-C44B-428A-9252-A11C365E2C56} = {4C68702C-1661-4AD9-83FD-E0B52B791969}
225+
{FC86D3AB-778D-45D7-AF36-1F89FC16DE55} = {4C68702C-1661-4AD9-83FD-E0B52B791969}
226+
{4D1F117D-48D7-47AD-9DAC-3B2DB45E628A} = {4C68702C-1661-4AD9-83FD-E0B52B791969}
227+
{44A166BD-01E9-4A4B-9BC5-7DE01B472E73} = {1C5D462D-168D-4D3F-B96E-CCE5517DB197}
228+
{472BC645-9E2F-4205-A571-4D9184747EC5} = {7F9E0AEA-721E-46F8-90ED-8EA8423647FB}
229+
EndGlobalSection
188230
GlobalSection(ExtensibilityGlobals) = postSolution
189231
SolutionGuid = {E20303B6-8AC9-4FFF-B645-4608309ADA94}
190232
EndGlobalSection

src/Cortex.Mediator.Behaviors.FluentValidation/Assets/andyX.png renamed to src/Cortex.Mediator.Behaviors.FluentValidation/Assets/cortex.png

File renamed without changes.

src/Cortex.Mediator.Behaviors.FluentValidation/Cortex.Mediator.Behaviors.FluentValidation.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<Version>1.0.0</Version>
2323
<PackageLicenseFile>license.md</PackageLicenseFile>
24-
<PackageIcon>andyX.png</PackageIcon>
24+
<PackageIcon>cortex.png</PackageIcon>
2525
<PackageId>Cortex.Mediator.Behaviors.FluentValidation</PackageId>
2626
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
2727
<IsPublishable>True</IsPublishable>
@@ -46,7 +46,7 @@
4646
</Content>
4747
</ItemGroup>
4848
<ItemGroup>
49-
<None Include="Assets\andyX.png">
49+
<None Include="Assets\cortex.png">
5050
<Pack>True</Pack>
5151
<PackagePath></PackagePath>
5252
</None>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Cortex.Mediator.DependencyInjection;
2+
3+
namespace Cortex.Mediator.Behaviors.FluentValidation.DependencyInjection
4+
{
5+
public static class MediatorOptionsExtensions
6+
{
7+
public static MediatorOptions AddFluentValidationBehaviors(this MediatorOptions options)
8+
{
9+
options.AddOpenCommandPipelineBehavior(typeof(ValidationCommandBehavior<,>))
10+
.AddOpenQueryPipelineBehavior(typeof(ValidationQueryBehavior<,>))
11+
.AddOpenCommandPipelineBehavior(typeof(ValidationCommandBehavior<>));
12+
13+
return options;
14+
}
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using FluentValidation;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using System;
4+
using System.Linq;
5+
6+
namespace Cortex.Mediator.Behaviors.FluentValidation.DependencyInjection
7+
{
8+
public static class ServiceCollectionExtensions
9+
{
10+
public static IServiceCollection AddFluentValidationValidators(this IServiceCollection services, Type[] validationAssemblyMarkerTypes)
11+
{
12+
services.AddValidatorsFromAssemblies(validationAssemblyMarkerTypes.Select(t => t.Assembly));
13+
return services;
14+
}
15+
}
16+
}

src/Cortex.Mediator.Behaviors.FluentValidation/ValidationCommandBehavior.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Cortex.Mediator.Commands;
22
using FluentValidation;
3-
using System;
43
using System.Collections.Generic;
54
using System.Linq;
65
using System.Threading;
@@ -16,12 +15,17 @@ public sealed class ValidationCommandBehavior<TCommand, TResult> : ICommandPipel
1615
{
1716
private readonly IEnumerable<IValidator<TCommand>> _validators;
1817

18+
public ValidationCommandBehavior(IEnumerable<IValidator<TCommand>> validators)
19+
{
20+
_validators = validators;
21+
}
1922

2023
public async Task<TResult> Handle(TCommand command, CommandHandlerDelegate<TResult> next, CancellationToken cancellationToken)
2124
{
2225
var context = new ValidationContext<TCommand>(command);
2326
var failures = _validators
24-
.Select(v => v.Validate(context))
27+
.Select(async v => await v.ValidateAsync(context))
28+
.Select(r => r.Result)
2529
.SelectMany(r => r.Errors)
2630
.Where(f => f != null)
2731
.ToList();

src/Cortex.Mediator.Behaviors.FluentValidation/ValidationQueryBehavior.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ public sealed class ValidationQueryBehavior<TQuery, TResult> : IQueryPipelineBeh
1313

1414
private readonly IEnumerable<IValidator<TQuery>> _validators;
1515

16+
public ValidationQueryBehavior(IEnumerable<IValidator<TQuery>> validators)
17+
{
18+
_validators = validators;
19+
}
20+
1621

1722
public async Task<TResult> Handle(TQuery query, QueryHandlerDelegate<TResult> next, CancellationToken cancellationToken)
1823
{
1924
var context = new ValidationContext<TQuery>(query);
2025
var failures = _validators
21-
.Select(v => v.Validate(context))
26+
.Select(async v => await v.ValidateAsync(context))
27+
.Select(r => r.Result)
2228
.SelectMany(r => r.Errors)
2329
.Where(f => f != null)
2430
.ToList();
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Cortex.Mediator.Commands;
2+
using FluentValidation;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
8+
namespace Cortex.Mediator.Behaviors
9+
{
10+
/// <summary>
11+
/// Pipeline behavior for validation command execution.
12+
/// </summary>
13+
public sealed class ValidationCommandBehavior<TCommand> : ICommandPipelineBehavior<TCommand>
14+
where TCommand : ICommand
15+
{
16+
private readonly IEnumerable<IValidator<TCommand>> _validators;
17+
18+
public ValidationCommandBehavior(IEnumerable<IValidator<TCommand>> validators)
19+
{
20+
_validators = validators;
21+
}
22+
23+
24+
public async Task Handle(TCommand command, CommandHandlerDelegate next, CancellationToken cancellationToken)
25+
{
26+
var context = new ValidationContext<TCommand>(command);
27+
var failures = _validators
28+
.Select(async v => await v.ValidateAsync(context))
29+
.Select(r => r.Result)
30+
.SelectMany(r => r.Errors)
31+
.Where(f => f != null)
32+
.ToList();
33+
34+
if (failures.Count() > 0)
35+
{
36+
var errors = failures
37+
.GroupBy(f => f.PropertyName)
38+
.ToDictionary(
39+
g => g.Key,
40+
g => g.Select(f => f.ErrorMessage).ToArray());
41+
42+
throw new Exceptions.ValidationException(errors);
43+
}
44+
45+
await next();
46+
}
47+
}
48+
}

src/Cortex.Mediator/DependencyInjection/ServiceCollectionExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ public static class ServiceCollectionExtensions
1515
{
1616
public static IServiceCollection AddCortexMediator(
1717
this IServiceCollection services,
18-
IConfiguration configuration,
1918
Type[] handlerAssemblyMarkerTypes,
20-
Action<MediatorOptions>? configure = null)
19+
Action<MediatorOptions> configure = null)
2120
{
2221
var options = new MediatorOptions();
2322
configure?.Invoke(options);
62 KB
Loading

0 commit comments

Comments
 (0)