Skip to content

Commit 38c1ccf

Browse files
committed
Updated Program.cs
1 parent 0f354cc commit 38c1ccf

3 files changed

Lines changed: 21 additions & 17 deletions

File tree

samples/EasyWay.Samples/EasyWay.Samples.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.2" />
2223
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
2324
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.9.0" />
2425
</ItemGroup>

samples/EasyWay.Samples/Program.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
using EasyWay.Samples;
2-
using EasyWay.Samples.Commands;
3-
using EasyWay.Samples.Commands.WithResult;
42
using EasyWay.Samples.Queries;
5-
/*
6-
var webKernelBuilder = WebKernelBuilder.Create(args);
3+
using Microsoft.AspNetCore.Mvc;
74

8-
var builder = webKernelBuilder.AppBuilder;
5+
var builder = WebApplication.CreateBuilder(args);
96

10-
webKernelBuilder.AddModule<SampleModule>();
7+
8+
9+
var kernel = Kernel.Create();
10+
11+
await kernel
12+
.AddModule<SampleModule>()
13+
.BuildAsync(builder.Services);
1114

1215
builder.Services.AddEndpointsApiExplorer();
1316
builder.Services.AddSwaggerGen();
1417

15-
var webKernel = await webKernelBuilder.BuildAsync();
18+
var app = builder.Build();
1619

17-
var app = webKernel.App;
18-
19-
// Configure the HTTP request pipeline.
2020
if (app.Environment.IsDevelopment())
2121
{
2222
app.UseSwagger();
2323
app.UseSwaggerUI();
2424
}
2525

26-
webKernel.MapCommand<SampleModule, SampleCommand>();
27-
webKernel.MapCommand<SampleModule, SampleCommandWithResult, SampleCommandResult>();
28-
webKernel.MapCommand<SampleModule, ErrorCommand>();
29-
webKernel.MapQuery<SampleModule, SampleQuery, SampleQueryResult>();
26+
app.UseHttpsRedirection();
27+
3028

29+
app.MapPost("/query", async ([FromBody] SampleQuery query, IModuleExecutor<SampleModule> executor) =>
30+
{
31+
return await executor.Execute(query);
32+
});
3133

3234

33-
await webKernel.RunAsync();
34-
*/
35+
app.Run();
3536

3637
Console.WriteLine("TEST");

source/EasyWay/Kernel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ private Kernel()
2323

2424
public static Kernel Create() => new Kernel();
2525

26-
public void AddModule<TModule>()
26+
public Kernel AddModule<TModule>()
2727
where TModule : EasyWayModule, new()
2828
{
2929
var configuration = _configuration.GetSection(typeof(TModule).Name);
3030

3131
var moduleExecutorType = new TModule().Initialize(_services, configuration);
3232

3333
_moduleExecutorTypes.Add(moduleExecutorType);
34+
35+
return this;
3436
}
3537

3638
public async Task BuildAsync(IServiceCollection services)

0 commit comments

Comments
 (0)