🎯 GamingHub.Application
Couche Application - Services métier et cas d'usage
📋 À implémenter ici
Services (Services/)
ITournamentService.cs+TournamentService.csITeamService.cs+TeamService.csIAuthService.cs+AuthService.cs
DTOs (DTOs/)
CreateTournamentDto.cs,TournamentDto.csCreateTeamDto.cs,TeamDto.csRegisterDto.cs,LoginDto.cs,AuthResponseDto.cs
Validators (Validators/)
CreateTournamentDtoValidator.cs- FluentValidationCreateTeamDtoValidator.csRegisterDtoValidator.csLoginDtoValidator.cs
Interfaces (Interfaces/)
ITournamentRepository.cs- Contrat repositoryITeamRepository.csIUserRepository.cs
⚠️ Règles importantes
- ✅ Dépend uniquement de Domain
- ❌ Ne connaît PAS Infrastructure
- ✅ Utilise FluentValidation pour valider les DTOs
- ✅ Services contiennent la logique applicative (orchestration)
📝 Exemple de service
public class TournamentService : ITournamentService
{
private readonly ITournamentRepository _tournamentRepository;
private readonly ILogger<TournamentService> _logger;
public TournamentService(
ITournamentRepository tournamentRepository,
ILogger<TournamentService> logger)
{
_tournamentRepository = tournamentRepository;
_logger = logger;
}
public async Task<TournamentDto> CreateAsync(CreateTournamentDto dto)
{
_logger.LogInformation("Creating tournament {Name}", dto.Name);
// Créer l'entité Domain
var tournament = new Tournament(dto.Name, dto.Game, dto.Description, ...);
// Persister via repository
await _tournamentRepository.AddAsync(tournament);
// Retourner DTO
return MapToDto(tournament);
}
}
📝 Exemple de validator
public class CreateTournamentDtoValidator : AbstractValidator<CreateTournamentDto>
{
public CreateTournamentDtoValidator()
{
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Name is required")
.MaximumLength(200);
RuleFor(x => x.StartDate)
.GreaterThan(DateTime.UtcNow)
.WithMessage("Start date must be in the future");
RuleFor(x => x.MaxTeams)
.GreaterThan(0)
.LessThanOrEqualTo(64);
}
}