Skip to content

Commit 048e851

Browse files
committed
2 parents 442ce40 + 755b3ff commit 048e851

File tree

6 files changed

+41
-53
lines changed

6 files changed

+41
-53
lines changed

Directory.Packages.props

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
<Project>
22
<ItemGroup>
3-
<PackageVersion Include="Ardalis.GuardClauses" Version="4.5.0" />
3+
<PackageVersion Include="Ardalis.GuardClauses" Version="4.6.0" />
44
<PackageVersion Include="Ardalis.HttpClientTestExtensions" Version="4.2.0" />
55
<PackageVersion Include="Ardalis.ListStartupServices" Version="1.1.4" />
6-
<PackageVersion Include="Ardalis.Result" Version="8.0.0" />
7-
<PackageVersion Include="Ardalis.Result.AspNetCore" Version="8.0.0" />
8-
<PackageVersion Include="Ardalis.SharedKernel" Version="1.4.0" />
6+
<PackageVersion Include="Ardalis.Result" Version="9.1.0" />
7+
<PackageVersion Include="Ardalis.Result.AspNetCore" Version="9.1.0" />
8+
<PackageVersion Include="Ardalis.SharedKernel" Version="1.5.0" />
99
<PackageVersion Include="Ardalis.SmartEnum" Version="8.0.0" />
1010
<PackageVersion Include="Ardalis.Specification" Version="8.0.0" />
1111
<PackageVersion Include="Ardalis.Specification.EntityFrameworkCore" Version="8.0.0" />
12-
<PackageVersion Include="coverlet.collector" Version="6.0.1" />
13-
<PackageVersion Include="FastEndpoints" Version="5.23.0" />
12+
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
13+
<PackageVersion Include="FastEndpoints" Version="5.27.0" />
1414
<PackageVersion Include="FastEndpoints.ApiExplorer" Version="2.2.0" />
15-
<PackageVersion Include="FastEndpoints.Swagger" Version="5.23.0" />
15+
<PackageVersion Include="FastEndpoints.Swagger" Version="5.27.0" />
1616
<PackageVersion Include="FastEndpoints.Swagger.Swashbuckle" Version="2.2.0" />
1717
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
18-
<PackageVersion Include="MailKit" Version="4.4.0" />
19-
<PackageVersion Include="MediatR" Version="12.2.0" />
20-
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.2" />
21-
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.2" />
22-
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.2" />
23-
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2" />
24-
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2" />
25-
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
26-
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
18+
<PackageVersion Include="MailKit" Version="4.7.1.1" />
19+
<PackageVersion Include="MediatR" Version="12.3.0" />
20+
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.7" />
21+
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.7" />
22+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.7" />
23+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.7" />
24+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.7" />
25+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.7" />
26+
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.7" />
2727
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
2828
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
2929
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
3030
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
31-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
32-
<PackageVersion Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.1" />
31+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
32+
<PackageVersion Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.3" />
3333
<PackageVersion Include="NSubstitute" Version="5.1.0" />
34-
<PackageVersion Include="ReportGenerator" Version="5.2.2" />
34+
<PackageVersion Include="ReportGenerator" Version="5.3.8" />
3535
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.1" />
3636
<PackageVersion Include="SQLite" Version="3.13.0" />
3737
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
3838
<PackageVersion Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
39-
<PackageVersion Include="xunit" Version="2.7.0" />
40-
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7" />
39+
<PackageVersion Include="xunit" Version="2.9.0" />
40+
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
4141
</ItemGroup>
4242
</Project>

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ By default the site uses HTTPS and expects you to have a self-signed developer c
2727
- [Table Of Contents](#table-of-contents)
2828
- [Give a Star! :star:](#give-a-star-star)
2929
- [Versions](#versions)
30-
- [Controllers and Razor Pages](#controllers-and-razor-pages)
31-
- [Add Ardalis.ApiEndpoints](#add-ardalisapiendpoints)
32-
- [Add Controllers](#add-controllers)
33-
- [Add Razor Pages](#add-razor-pages)
3430
- [Learn More](#learn-more)
3531
- [Getting Started](#getting-started)
3632
- [Using the dotnet CLI template](#using-the-dotnet-cli-template)
33+
- [What about Controllers and Razor Pages?](#what-about-controllers-and-razor-pages)
34+
- [Add Ardalis.ApiEndpoints](#add-ardalisapiendpoints)
35+
- [Add Controllers](#add-controllers)
36+
- [Add Razor Pages](#add-razor-pages)
3737
- [Using the GitHub Repository](#using-the-github-repository)
3838
- [Running Migrations](#running-migrations)
3939
- [Goals](#goals)
@@ -64,7 +64,7 @@ The main branch is now using .NET 8. If you need a previous version use one of t
6464
- [5.0](https://github.com/ardalis/CleanArchitecture/releases/tag/dotnet-core-5)
6565
- [3.1](https://github.com/ardalis/CleanArchitecture/tree/dotnet-core-3.1)
6666
- [2.2](https://github.com/ardalis/CleanArchitecture/tree/dotnet-core-2.2)
67-
- [2.0](https://github.com/ardalis/CleanArchitecture/tree/dotnet-core-2.0)\
67+
- [2.0](https://github.com/ardalis/CleanArchitecture/tree/dotnet-core-2.0)
6868

6969
## Learn More
7070

@@ -111,7 +111,7 @@ Thanks [@dahlsailrunner](https://github.com/dahlsailrunner) for your help gettin
111111

112112
## What about Controllers and Razor Pages?
113113

114-
As of version 9, this solution template only includes support for API Endpoints using the FastEndpoints library. If you want to use my ApiEndpoints library, Razor Pages, and/or Controllers you can use the last template that included them, version 7.1. Alternately, they're easily added to this template after installation.
114+
As of version 9, this solution template only includes support for API Endpoints using the FastEndpoints library. If you want to use my ApiEndpoints library, Razor Pages, and/or Controllers you can use the last template that included them, [version 7.1](https://www.nuget.org/packages/Ardalis.CleanArchitecture.Template/7.1.0). Alternately, they're easily added to this template after installation.
115115

116116
### Add Ardalis.ApiEndpoints
117117

@@ -237,7 +237,7 @@ The Core project is the center of the Clean Architecture design, and all other p
237237

238238
An optional project, I've included it because many folks were demanding it and it's easier to remove than to add later. This is also often referred to as the *Application* or *Application Services* layer. The Use Cases project is organized following CQRS into Commands and Queries. Commands mutate the domain model and thus should always use Repository abstractions for their data access. Queries are readonly, and thus do not need to use the repository pattern, but instead can use whatever query service or approach is most convenient. However, since the Use Cases project is set up to depend on Core and not directly on Infrastructure, there will still need to be abstractions defined for its data access. And it *can* use things like specifications, which can sometimes help encapsulate query logic as well as result type mapping. But it doesn't *have* to use repository/specification - it can just issue a SQL query or call a stored procedure if that's the most efficient way to get the data.
239239

240-
Although this is an option project to include (without it, your API endpoints would just work directly with the domain model or query services), it does provide a nice UI-ignorant place to add automated tests.
240+
Although this is an optional project to include (without it, your API endpoints would just work directly with the domain model or query services), it does provide a nice UI-ignorant place to add automated tests.
241241

242242
## The Infrastructure Project
243243

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Clean.Architecture.Core.ContributorAggregate;
22
using Microsoft.EntityFrameworkCore;
3-
using Microsoft.Extensions.DependencyInjection;
43

54
namespace Clean.Architecture.Infrastructure.Data;
65

@@ -9,27 +8,16 @@ public static class SeedData
98
public static readonly Contributor Contributor1 = new("Ardalis");
109
public static readonly Contributor Contributor2 = new("Snowfrog");
1110

12-
public static void Initialize(IServiceProvider serviceProvider)
11+
public static async Task InitializeAsync(AppDbContext dbContext)
1312
{
14-
using (var dbContext = new AppDbContext(
15-
serviceProvider.GetRequiredService<DbContextOptions<AppDbContext>>(), null))
16-
{
17-
if (dbContext.Contributors.Any()) return; // DB has been seeded
13+
if (await dbContext.Contributors.AnyAsync()) return; // DB has been seeded
1814

19-
PopulateTestData(dbContext);
20-
}
15+
await PopulateTestDataAsync(dbContext);
2116
}
22-
public static void PopulateTestData(AppDbContext dbContext)
23-
{
24-
foreach (var contributor in dbContext.Contributors)
25-
{
26-
dbContext.Remove(contributor);
27-
}
28-
dbContext.SaveChanges();
29-
30-
dbContext.Contributors.Add(Contributor1);
31-
dbContext.Contributors.Add(Contributor2);
3217

33-
dbContext.SaveChanges();
18+
public static async Task PopulateTestDataAsync(AppDbContext dbContext)
19+
{
20+
dbContext.Contributors.AddRange([Contributor1, Contributor2]);
21+
await dbContext.SaveChangesAsync();
3422
}
3523
}

src/Clean.Architecture.Web/Contributors/GetById.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public override void Configure()
2323
public override async Task HandleAsync(GetContributorByIdRequest request,
2424
CancellationToken cancellationToken)
2525
{
26-
var command = new GetContributorQuery(request.ContributorId);
26+
var query = new GetContributorQuery(request.ContributorId);
2727

28-
var result = await _mediator.Send(command, cancellationToken);
28+
var result = await _mediator.Send(query, cancellationToken);
2929

3030
if (result.Status == ResultStatus.NotFound)
3131
{

src/Clean.Architecture.Web/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@
7676

7777
app.UseHttpsRedirection();
7878

79-
SeedDatabase(app);
79+
await SeedDatabase(app);
8080

8181
app.Run();
8282

83-
static void SeedDatabase(WebApplication app)
83+
static async Task SeedDatabase(WebApplication app)
8484
{
8585
using var scope = app.Services.CreateScope();
8686
var services = scope.ServiceProvider;
@@ -90,7 +90,7 @@ static void SeedDatabase(WebApplication app)
9090
var context = services.GetRequiredService<AppDbContext>();
9191
// context.Database.Migrate();
9292
context.Database.EnsureCreated();
93-
SeedData.Initialize(services);
93+
await SeedData.InitializeAsync(context);
9494
}
9595
catch (Exception ex)
9696
{

tests/Clean.Architecture.FunctionalTests/CustomWebApplicationFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected override IHost CreateHost(IHostBuilder builder)
4747
//if (!db.ToDoItems.Any())
4848
//{
4949
// Seed the database with test data.
50-
SeedData.PopulateTestData(db);
50+
SeedData.PopulateTestDataAsync(db).Wait();
5151
//}
5252
}
5353
catch (Exception ex)

0 commit comments

Comments
 (0)