Skip to content

Commit becc9c0

Browse files
authored
Removed module from handlers (#74)
* Removed module from handlers * Updated ConcurrencyConflictValidator * Changed QueryExecutor * Changed command executor
1 parent 38c1ccf commit becc9c0

29 files changed

Lines changed: 101 additions & 83 deletions

samples/EasyWay.Samples/Commands/ErrorCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace EasyWay.Samples.Commands
22
{
3-
public class ErrorCommand : Command<SampleModule>
3+
public class ErrorCommand : Command
44
{
55

66
}

samples/EasyWay.Samples/Commands/ErrorCommandHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace EasyWay.Samples.Commands
44
{
5-
public class ErrorCommandHandler : ICommandHandler<SampleModule, ErrorCommand>
5+
public class ErrorCommandHandler : ICommandHandler<ErrorCommand>
66
{
77
public Task<CommandResult> Handle(ErrorCommand command)
88
{

samples/EasyWay.Samples/Commands/SampleCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace EasyWay.Samples.Commands
22
{
3-
public class SampleCommand : Command<SampleModule>, IWithConcurrencyToken
3+
public class SampleCommand : Command, IWithConcurrencyToken
44
{
55
public Guid Id { get; init; }
66

samples/EasyWay.Samples/Commands/SampleCommandHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace EasyWay.Samples.Commands
55
{
6-
internal sealed class SampleCommandHandler : ICommandHandler<SampleModule, SampleCommand>
6+
internal sealed class SampleCommandHandler : ICommandHandler<SampleCommand>
77
{
88
private readonly ICancellationContext _cancellationContext;
99

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
namespace EasyWay.Samples.Commands.WithResult
22
{
3-
public class SampleCommandWithResult : Command<SampleModule, SampleCommandResult>
3+
public class SampleCommandWithResult : Command<SampleCommandResult>, IWithConcurrencyToken
44
{
55
public string Name { get; init; }
6+
7+
public short ConcurrencyToken { get; init; }
68
}
79
}

samples/EasyWay.Samples/Commands/WithResult/SampleCommandWithResultHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
namespace EasyWay.Samples.Commands.WithResult
33
{
4-
public sealed class SampleCommandWithResultHandler : ICommandHandler<SampleModule, SampleCommandWithResult, SampleCommandResult>
4+
public sealed class SampleCommandWithResultHandler : ICommandHandler<SampleCommandWithResult, SampleCommandResult>
55
{
66
public Task<CommandResult<SampleCommandResult>> Handle(SampleCommandWithResult command)
77
{

samples/EasyWay.Samples/Program.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using EasyWay.Samples;
2+
using EasyWay.Samples.Commands;
3+
using EasyWay.Samples.Commands.WithResult;
24
using EasyWay.Samples.Queries;
35
using Microsoft.AspNetCore.Mvc;
46

@@ -14,6 +16,7 @@ await kernel
1416

1517
builder.Services.AddEndpointsApiExplorer();
1618
builder.Services.AddSwaggerGen();
19+
builder.Services.AddEasyWayWebApi();
1720

1821
var app = builder.Build();
1922

@@ -25,12 +28,27 @@ await kernel
2528

2629
app.UseHttpsRedirection();
2730

31+
//app.UseEasyWay();
2832

29-
app.MapPost("/query", async ([FromBody] SampleQuery query, IModuleExecutor<SampleModule> executor) =>
33+
34+
app.MapPost("/query", async ([FromBody] SampleQuery query, IModuleExecutor<SampleModule> executor, IWebApiResultMapper mapper) =>
35+
{
36+
var x = await executor.Query<SampleQuery, SampleQueryResult>(query);
37+
38+
return mapper.Map(x);
39+
});
40+
41+
app.MapPost("/command", async ([FromBody] SampleCommand command, IModuleExecutor<SampleModule> executor, IWebApiResultMapper mapper) =>
3042
{
31-
return await executor.Execute(query);
43+
return await executor.Command(command);
3244
});
3345

46+
app.MapPost("/commandwithresult", async ([FromBody] SampleCommandWithResult command, IModuleExecutor<SampleModule> executor, IWebApiResultMapper mapper) =>
47+
{
48+
var x = await executor.Command<SampleCommandWithResult, SampleCommandResult>(command);
49+
50+
return mapper.Map(x);
51+
});
3452

3553
app.Run();
3654

samples/EasyWay.Samples/Queries/SampleQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace EasyWay.Samples.Queries
22
{
3-
public class SampleQuery : Query<SampleModule, SampleQueryResult>
3+
public class SampleQuery : Query<SampleQueryResult>
44
{
55
public required string Name { get; init; }
66

samples/EasyWay.Samples/Queries/SampleQueryHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace EasyWay.Samples.Queries
22
{
3-
public class SampleQueryHandler : IQueryHandler<SampleModule, SampleQuery, SampleQueryResult>
3+
public class SampleQueryHandler : IQueryHandler<SampleQuery, SampleQueryResult>
44
{
55
public Task<QueryResult<SampleQueryResult>> Handle(SampleQuery query)
66
{

samples/EasyWay.Samples/SampleModule.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using EasyWay.Samples.Databases;
1+
using EasyWay.Samples.Commands;
2+
using EasyWay.Samples.Databases;
23
using Microsoft.EntityFrameworkCore;
34
using System.Reflection;
45

@@ -8,7 +9,8 @@ public sealed class SampleModule : EasyWayModule
89
{
910
protected override IEnumerable<Assembly> Assemblies => new List<Assembly>
1011
{
11-
typeof(SampleModule).Assembly
12+
typeof(SampleModule).Assembly,
13+
typeof(SampleCommand).Assembly
1214
};
1315

1416
protected override void ConfigureDependencies(IServiceCollection services, IConfiguration configuration)

0 commit comments

Comments
 (0)