Skip to content

Commit f607c0a

Browse files
authored
Merge pull request #103 from denismichealk/aspnetcore-realworld-example-app-net7
Aspnetcore realworld example app net7
2 parents cb3bec9 + 4b4c6ec commit f607c0a

26 files changed

+299
-237
lines changed

.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ dotnet_diagnostic.CA2249.severity = error
288288
dotnet_diagnostic.CS0169.severity = error
289289
dotnet_diagnostic.CS0219.severity = error
290290
dotnet_diagnostic.CS1998.severity = error
291-
dotnet_diagnostic.CS8602.severity = error
292-
dotnet_diagnostic.CS8604.severity = error
291+
dotnet_diagnostic.CS8602.severity = Default
292+
dotnet_diagnostic.CS8604.severity = Default
293293
dotnet_diagnostic.CS8618.severity = error
294294
dotnet_diagnostic.CS0618.severity = error
295295
dotnet_diagnostic.CS1998.severity = error

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,7 @@ tools
283283
.env
284284

285285
.DS_Store
286+
287+
# sqlite database
288+
*.db-shm
289+
*.db-wal

Dockerfile

Lines changed: 0 additions & 17 deletions
This file was deleted.

build/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
2+
3+
FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base
4+
WORKDIR /app
5+
6+
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
7+
WORKDIR /src
8+
COPY ["build/build.csproj", "build/"]
9+
RUN dotnet restore "build/build.csproj"
10+
COPY . .
11+
WORKDIR "/src/build"
12+
RUN dotnet build "build.csproj" -c Release -o /app/build
13+
14+
FROM build AS publish
15+
RUN dotnet publish "build.csproj" -c Release -o /app/publish /p:UseAppHost=false
16+
17+
FROM base AS final
18+
WORKDIR /app
19+
EXPOSE 5000
20+
21+
ENTRYPOINT ["dotnet", "Conduit.dll"]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"profiles": {
3+
"build": {
4+
"commandName": "Project"
5+
},
6+
"Docker": {
7+
"commandName": "Docker"
8+
}
9+
}
10+
}

build/build.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net5.0</TargetFramework>
3+
<TargetFramework>net7.0</TargetFramework>
44
<OutputType>Exe</OutputType>
5+
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
56
</PropertyGroup>
67

78
<ItemGroup>
8-
<PackageReference Include="Bullseye" Version="3.8.0" />
9-
<PackageReference Include="Glob" Version="1.1.8" />
10-
<PackageReference Include="SimpleExec" Version="8.0.0" />
9+
<PackageReference Include="Bullseye" Version="4.2.1" />
10+
<PackageReference Include="Glob" Version="1.1.9" />
11+
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
12+
<PackageReference Include="SimpleExec" Version="11.0.0" />
1113
</ItemGroup>
1214
</Project>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "5.0.301",
3+
"version": "7.0.306",
44
"rollForward": "latestFeature"
55
}
66
}

src/Conduit/Conduit.csproj

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>net5.0</TargetFramework>
3+
<TargetFramework>net7.0</TargetFramework>
44
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
55
<Nullable>enable</Nullable>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="AutoMapper" Version="10.1.1" />
10-
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
11-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.9" />
12-
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.9" />
13-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.9" />
14-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.9" />
15-
<PackageReference Include="Serilog" Version="2.10.0" />
16-
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
17-
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
18-
<PackageReference Include="FluentValidation.AspNetCore" Version="10.3.3" />
19-
<PackageReference Include="MediatR" Version="9.0.0" />
20-
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
21-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.1" />
9+
<PackageReference Include="AutoMapper" Version="12.0.1" />
10+
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
11+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.10" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.10" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.10" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.10" />
15+
<PackageReference Include="Serilog" Version="3.0.1" />
16+
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
17+
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
18+
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
19+
<PackageReference Include="MediatR" Version="12.1.1" />
20+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
2221
</ItemGroup>
2322

2423
<ItemGroup>

src/Conduit/Features/Articles/ArticleExtensions.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ namespace Conduit.Features.Articles
66
{
77
public static class ArticleExtensions
88
{
9-
public static IQueryable<Article> GetAllData(this DbSet<Article> articles)
10-
{
11-
return articles
9+
public static IQueryable<Article> GetAllData(this DbSet<Article> articles) => articles
1210
.Include(x => x.Author)
1311
.Include(x => x.ArticleFavorites)
1412
.Include(x => x.ArticleTags)
1513
.AsNoTracking();
16-
}
1714
}
1815
}

src/Conduit/Features/Articles/Delete.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,23 @@ public record Command(string Slug) : IRequest;
1515

1616
public class CommandValidator : AbstractValidator<Command>
1717
{
18-
public CommandValidator()
19-
{
20-
RuleFor(x => x.Slug).NotNull().NotEmpty();
21-
}
18+
public CommandValidator() => RuleFor(x => x.Slug).NotNull().NotEmpty();
2219
}
2320

2421
public class QueryHandler : IRequestHandler<Command>
2522
{
2623
private readonly ConduitContext _context;
2724

28-
public QueryHandler(ConduitContext context)
29-
{
30-
_context = context;
31-
}
25+
public QueryHandler(ConduitContext context) => _context = context;
3226

33-
public async Task<Unit> Handle(Command message, CancellationToken cancellationToken)
27+
public async Task Handle(Command message, CancellationToken cancellationToken)
3428
{
3529
var article = await _context.Articles
36-
.FirstOrDefaultAsync(x => x.Slug == message.Slug, cancellationToken);
37-
38-
if (article == null)
39-
{
40-
throw new RestException(HttpStatusCode.NotFound, new { Article = Constants.NOT_FOUND });
41-
}
30+
.FirstOrDefaultAsync(x => x.Slug == message.Slug, cancellationToken) ?? throw new RestException(HttpStatusCode.NotFound, new { Article = Constants.NOT_FOUND });
4231

4332
_context.Articles.Remove(article);
4433
await _context.SaveChangesAsync(cancellationToken);
45-
return Unit.Value;
34+
await Task.FromResult(Unit.Value);
4635
}
4736
}
4837
}

0 commit comments

Comments
 (0)