Skip to content

Commit 54d4699

Browse files
committed
Atualização de versões e refatoração de código
* Atualização de versões - Alteradas versões de `WorkContextVer`, `ProblemsVer` e `GenVer` no `Directory.Build.props`. * Modificações na configuração do serviço - Substituído `RoyalCode.WorkContext` por `RoyalCode.SmartCommands.WorkContext.Extensions`. - Alterada configuração para usar `ConfigureDbContextWithService()` e adicionado `AddUnitOfWorkAdapter()`. * Novos endpoints - Adicionado mapeamento de endpoint para autores em `BlogsEndpoints.cs`. * Refatoração do contexto de trabalho - Refatorado `ConfigureBlogs` para usar `ConfigureModel` e atualizado repositório. - Introduzida a classe `BlogMapping` para definir relacionamento entre `Blog` e `Post`.
1 parent 293e3aa commit 54d4699

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

RoyalCode.Examples/Directory.Build.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<Project>
22
<PropertyGroup>
33
<AspNetVer>9.0.0</AspNetVer>
4-
<WorkContextVer>1.0.0-preview-9.0</WorkContextVer>
5-
<ProblemsVer>1.0.0-preview-4.3</ProblemsVer>
6-
<GenVer>0.0.1</GenVer>
4+
<WorkContextVer>0.8.0</WorkContextVer>
5+
<ProblemsVer>1.0.0-preview-4.4</ProblemsVer>
6+
<GenVer>0.0.2</GenVer>
77
<SqliteVer>9.0.7</SqliteVer>
88
<ScalarVer>2.6.3</ScalarVer>
99
</PropertyGroup>

RoyalCode.Examples/RoyalCode.Examples.Api/Program.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using RoyalCode.Examples.Api.EF;
22
using RoyalCode.Examples.Blogs.Api;
33
using RoyalCode.Examples.Blogs.Infra.Persistence;
4-
using RoyalCode.WorkContext;
4+
using RoyalCode.SmartCommands.WorkContext.Extensions;
55
using Scalar.AspNetCore;
66

77
var builder = WebApplication.CreateBuilder(args);
@@ -10,8 +10,9 @@
1010
builder.Services.AddBlobs();
1111

1212
builder.Services.AddWorkContext<AppDbContext>()
13-
.ConfigureWithService()
14-
.ConfigureBlogs();
13+
.ConfigureDbContextWithService()
14+
.ConfigureBlogs()
15+
.AddUnitOfWorkAdapter();
1516

1617
var app = builder.Build();
1718

RoyalCode.Examples/RoyalCode.Examples.Blogs/Api/BlogsEndpoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ public static partial class BlogsEndpoints
99
public static void MapBlob(this IEndpointRouteBuilder app)
1010
{
1111
app.MapHelloGroup();
12+
app.MapAuthorsGroup();
1213
}
1314
}
Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.EntityFrameworkCore;
2+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
23
using RoyalCode.Examples.Blogs.Core.Blogs;
34
using RoyalCode.Examples.Blogs.Core.Support;
45
using RoyalCode.WorkContext.EntityFramework.Configurations;
@@ -7,19 +8,35 @@ namespace RoyalCode.Examples.Blogs.Infra.Persistence;
78

89
public static class ConfigureWorkContext
910
{
10-
1111
public static IWorkContextBuilder<TDbContext> ConfigureBlogs<TDbContext>(this IWorkContextBuilder<TDbContext> builder)
1212
where TDbContext : DbContext
1313
{
14-
builder.ConfigureRepositories(b =>
15-
{
16-
b.Add<Blog>()
17-
.Add<Post>()
18-
.Add<Core.Blogs.Thread>()
19-
.Add<Comment>()
20-
.Add<Author>();
21-
});
14+
builder
15+
.ConfigureModel(b =>
16+
{
17+
b.ApplyConfigurationsFromAssembly(typeof(ConfigureWorkContext).Assembly);
18+
})
19+
.ConfigureRepositories(b =>
20+
{
21+
b.Add<Blog>()
22+
.Add<Post>()
23+
.Add<Core.Blogs.Thread>()
24+
.Add<Comment>()
25+
.Add<Author>();
26+
});
2227

2328
return builder;
2429
}
2530
}
31+
32+
public class BlogMapping : IEntityTypeConfiguration<Blog>
33+
{
34+
public void Configure(EntityTypeBuilder<Blog> builder)
35+
{
36+
builder
37+
.HasMany(b => b.Posts)
38+
.WithOne(p => p.Blog)
39+
.HasForeignKey("BlogId")
40+
.OnDelete(DeleteBehavior.Cascade);
41+
}
42+
}

0 commit comments

Comments
 (0)