Skip to content

Conversation

@devin-ai-integration
Copy link

Phase 1: Replace GenericServices with Custom Services, MediatR, and FluentValidation

Summary

This PR implements Phase 1 of the migration plan to replace GenericServices (v1.0.9, not .NET Core compatible) with a modern architecture. A new SampleWebApp.Core .NET Standard 2.0 project has been created containing:

  • Base classes: BaseDto, BaseQuery, BaseCommand for consistent patterns
  • Result types: CreateResult, UpdateResult, DeleteResult, PagedResult, SuccessOrErrors for operation outcomes
  • DTOs: PostDto, SimplePostDto, TagDto, BlogDto mirroring existing ServiceLayer DTOs
  • Service interfaces: Generic (IListService, IDetailService, etc.) and domain-specific (IPostService, ITagService, IBlogService)
  • MediatR handlers: Full CQRS implementation with queries and commands for Posts, Tags, and Blogs
  • Service implementations: PostService, TagService, BlogService using an IDbContextAdapter abstraction
  • FluentValidation validators: PostValidator, TagValidator, BlogValidator with business rules from existing code
  • Anti-corruption layer: GenericServicesAdapter for gradual migration
  • DI configuration: ServiceCollectionExtensions.AddCoreServices()

Package versions were adjusted for .NET Standard 2.0 compatibility: MediatR 9.0.0, AutoMapper 10.1.1, FluentValidation 10.4.0.

Review & Testing Checklist for Human

  • IDbContextAdapter pattern review: Services depend on IDbContextAdapter interface with entity types (PostEntity, TagEntity, BlogEntity) defined in the Core project. No implementation exists yet - this is intentional to avoid DataLayer coupling. Verify this approach is acceptable for Phase 2 integration.

  • DTO structure validation: DTOs have both Id (from BaseDto) and entity-specific IDs (PostId, TagId, BlogId). Confirm this dual-ID pattern won't cause issues when mapping to/from existing ServiceLayer DTOs.

  • Validator logic review: PostValidator includes business rules (no "!" in title, no "sheep/lamb/cow/calf" in content) copied from existing code. Verify these match current validation requirements.

  • GenericServicesAdapter completeness: Currently only implements Post operations. Confirm whether Tag/Blog adapter methods are needed for Phase 1.

  • Build verification: Run dotnet build SampleWebApp.Core/SampleWebApp.Core.csproj to confirm compilation succeeds.

Recommended test plan: Since this is Phase 1 (infrastructure only), functional testing requires Phase 2 implementation. For now, verify the project builds and review the code structure matches the specification document.

Notes

  • This PR adds the foundation but does not modify existing controllers - they still use GenericServices
  • Phase 2 will implement IDbContextAdapter and wire up controllers to use the new services
  • No unit tests included in this phase

Link to Devin run: https://app.devin.ai/sessions/7a2a40985384430e85b04122e904bb90
Requested by: Abhay Aggarwal (abhay.aggarwal@cognition.ai) / @abhay-codeium

…ntValidation

Phase 1 implementation to replace GenericServices with modern .NET Core-compatible architecture:

- Create SampleWebApp.Core .NET Standard 2.0 project
- Add NuGet packages: MediatR 9.0.0, AutoMapper 10.1.1, FluentValidation 10.4.0
- Implement base classes (BaseDto, BaseQuery, BaseCommand)
- Implement result types (CreateResult, UpdateResult, DeleteResult, PagedResult, SuccessOrErrors)
- Create DTOs (PostDto, SimplePostDto, TagDto, BlogDto)
- Create generic service interfaces (IListService, IDetailService, ICreateService, IUpdateService, IDeleteService)
- Create domain-specific service interfaces (IPostService, ITagService, IBlogService)
- Implement MediatR queries and commands for Posts, Tags, and Blogs
- Implement MediatR handlers for all queries and commands
- Implement service classes (PostService, TagService, BlogService) using IDbContextAdapter pattern
- Implement FluentValidation validators (PostValidator, TagValidator, BlogValidator)
- Create AutoMapper profiles for entity-to-DTO mapping
- Create anti-corruption layer (GenericServicesAdapter)
- Configure dependency injection (ServiceCollectionExtensions)

Co-Authored-By: Abhay Aggarwal <abhay.aggarwal@codeium.com>
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant