160 lines
3.3 KiB
Markdown
160 lines
3.3 KiB
Markdown
|
|
# DV-002: Configuración Solución .NET 10
|
||
|
|
|
||
|
|
**Proyecto:** Sistema de Registro de Estudiantes
|
||
|
|
**Fecha:** 2026-01-07
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 1. Crear Solución y Proyectos
|
||
|
|
|
||
|
|
```bash
|
||
|
|
cd src/backend
|
||
|
|
|
||
|
|
# Crear solución
|
||
|
|
dotnet new sln -n StudentEnrollment
|
||
|
|
|
||
|
|
# Crear proyectos
|
||
|
|
dotnet new classlib -n Domain -f net10.0
|
||
|
|
dotnet new classlib -n Application -f net10.0
|
||
|
|
dotnet new classlib -n Adapters.Driving.Api -f net10.0
|
||
|
|
dotnet new classlib -n Adapters.Driven.Persistence -f net10.0
|
||
|
|
dotnet new web -n Host -f net10.0
|
||
|
|
|
||
|
|
# Agregar a solución
|
||
|
|
dotnet sln add Domain/Domain.csproj
|
||
|
|
dotnet sln add Application/Application.csproj
|
||
|
|
dotnet sln add Adapters.Driving.Api/Adapters.Driving.Api.csproj
|
||
|
|
dotnet sln add Adapters.Driven.Persistence/Adapters.Driven.Persistence.csproj
|
||
|
|
dotnet sln add Host/Host.csproj
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 2. Referencias entre Proyectos
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# Application → Domain
|
||
|
|
dotnet add Application reference Domain
|
||
|
|
|
||
|
|
# Adapters.Driving.Api → Application
|
||
|
|
dotnet add Adapters.Driving.Api reference Application
|
||
|
|
|
||
|
|
# Adapters.Driven.Persistence → Domain
|
||
|
|
dotnet add Adapters.Driven.Persistence reference Domain
|
||
|
|
|
||
|
|
# Host → Todos
|
||
|
|
dotnet add Host reference Application
|
||
|
|
dotnet add Host reference Adapters.Driving.Api
|
||
|
|
dotnet add Host reference Adapters.Driven.Persistence
|
||
|
|
```
|
||
|
|
|
||
|
|
```
|
||
|
|
Host
|
||
|
|
├── Adapters.Driving.Api → Application → Domain
|
||
|
|
└── Adapters.Driven.Persistence ────────→ Domain
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 3. Paquetes NuGet por Proyecto
|
||
|
|
|
||
|
|
### Domain (sin dependencias externas)
|
||
|
|
```xml
|
||
|
|
<!-- Solo C# puro -->
|
||
|
|
```
|
||
|
|
|
||
|
|
### Application
|
||
|
|
```xml
|
||
|
|
<PackageReference Include="FluentValidation" />
|
||
|
|
<PackageReference Include="Mapster" />
|
||
|
|
<PackageReference Include="MediatR" />
|
||
|
|
```
|
||
|
|
|
||
|
|
### Adapters.Driven.Persistence
|
||
|
|
```xml
|
||
|
|
<PackageReference Include="Microsoft.EntityFrameworkCore" />
|
||
|
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
|
||
|
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" />
|
||
|
|
```
|
||
|
|
|
||
|
|
### Adapters.Driving.Api
|
||
|
|
```xml
|
||
|
|
<PackageReference Include="HotChocolate.AspNetCore" />
|
||
|
|
<PackageReference Include="HotChocolate.Data" />
|
||
|
|
<PackageReference Include="HotChocolate.Data.EntityFramework" />
|
||
|
|
```
|
||
|
|
|
||
|
|
### Host
|
||
|
|
```xml
|
||
|
|
<PackageReference Include="Serilog.AspNetCore" />
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 4. Directory.Build.props (Raíz backend)
|
||
|
|
|
||
|
|
```xml
|
||
|
|
<Project>
|
||
|
|
<PropertyGroup>
|
||
|
|
<TargetFramework>net10.0</TargetFramework>
|
||
|
|
<Nullable>enable</Nullable>
|
||
|
|
<ImplicitUsings>enable</ImplicitUsings>
|
||
|
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||
|
|
</PropertyGroup>
|
||
|
|
</Project>
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 5. Program.cs (Host)
|
||
|
|
|
||
|
|
```csharp
|
||
|
|
var builder = WebApplication.CreateBuilder(args);
|
||
|
|
|
||
|
|
// Services
|
||
|
|
builder.Services.AddApplication();
|
||
|
|
builder.Services.AddPersistence(builder.Configuration);
|
||
|
|
builder.Services.AddGraphQLApi();
|
||
|
|
|
||
|
|
// CORS
|
||
|
|
builder.Services.AddCors(options =>
|
||
|
|
{
|
||
|
|
options.AddDefaultPolicy(policy =>
|
||
|
|
policy.WithOrigins("http://localhost:4200")
|
||
|
|
.AllowAnyHeader()
|
||
|
|
.AllowAnyMethod());
|
||
|
|
});
|
||
|
|
|
||
|
|
var app = builder.Build();
|
||
|
|
|
||
|
|
app.UseCors();
|
||
|
|
app.MapGraphQL();
|
||
|
|
|
||
|
|
app.Run();
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 6. Comandos de Desarrollo
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# Restaurar dependencias
|
||
|
|
dotnet restore
|
||
|
|
|
||
|
|
# Build
|
||
|
|
dotnet build
|
||
|
|
|
||
|
|
# Ejecutar
|
||
|
|
dotnet run --project Host
|
||
|
|
|
||
|
|
# Watch mode
|
||
|
|
dotnet watch run --project Host
|
||
|
|
|
||
|
|
# Tests
|
||
|
|
dotnet test
|
||
|
|
|
||
|
|
# Migraciones EF
|
||
|
|
dotnet ef migrations add Initial -p Adapters.Driven.Persistence -s Host
|
||
|
|
dotnet ef database update -p Adapters.Driven.Persistence -s Host
|
||
|
|
```
|