Document rationale against generic CRUD/service pattern
Added detailed comments in CatalogService and ICatalogService explaining why a generic CRUD base service or repository is not suitable for this solution, due to entity-specific domain logic and stored procedure usage. Removed the previous Copilot comment from CatalogRepository. No functional changes; updates are for architectural clarity.
This commit is contained in:
@@ -5,6 +5,22 @@ using DbFirst.Domain.Entities;
|
|||||||
namespace DbFirst.Application.Catalogs;
|
namespace DbFirst.Application.Catalogs;
|
||||||
|
|
||||||
//TODO: create generic service to reduce code duplication
|
//TODO: create generic service to reduce code duplication
|
||||||
|
|
||||||
|
/* Copilot's Response:
|
||||||
|
A generic CRUD base service adds little value in your case:
|
||||||
|
|
||||||
|
Pros:
|
||||||
|
• Less boilerplate for simple entities without special logic.
|
||||||
|
• Uniform CRUD signatures.
|
||||||
|
|
||||||
|
Cons/Practical here:
|
||||||
|
• Domain logic differs per entity(unique title check, setting audit fields, forbidding title changes, stored procs with output GUID).
|
||||||
|
• Generic services tend to be diluted by virtual methods/hooks for special cases—ending up with per-entity overrides and little real gain.
|
||||||
|
• With stored procedures and output parameters, the pattern doesn’t fit cleanly because operations aren’t symmetric (separate procs for insert/update/delete).
|
||||||
|
|
||||||
|
Conclusion: For this solution a generic service would be more overhead than benefit. If you later have multiple very similar entities without special logic,
|
||||||
|
you could consider a lightweight generic interface/base; for now, the specialized service implementation is cleaner. */
|
||||||
|
|
||||||
//TODO: implement CQRS pattern with MediatR
|
//TODO: implement CQRS pattern with MediatR
|
||||||
public class CatalogService : ICatalogService
|
public class CatalogService : ICatalogService
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,22 @@
|
|||||||
namespace DbFirst.Application.Catalogs;
|
namespace DbFirst.Application.Catalogs;
|
||||||
|
|
||||||
//TODO: create generic service to reduce code duplication
|
//TODO: create generic service to reduce code duplication
|
||||||
|
|
||||||
|
/* Copilot's Response:
|
||||||
|
A generic CRUD base service adds little value in your case:
|
||||||
|
|
||||||
|
Pros:
|
||||||
|
• Less boilerplate for simple entities without special logic.
|
||||||
|
• Uniform CRUD signatures.
|
||||||
|
|
||||||
|
Cons/Practical here:
|
||||||
|
• Domain logic differs per entity(unique title check, setting audit fields, forbidding title changes, stored procs with output GUID).
|
||||||
|
• Generic services tend to be diluted by virtual methods/hooks for special cases—ending up with per-entity overrides and little real gain.
|
||||||
|
• With stored procedures and output parameters, the pattern doesn’t fit cleanly because operations aren’t symmetric (separate procs for insert/update/delete).
|
||||||
|
|
||||||
|
Conclusion: For this solution a generic service would be more overhead than benefit. If you later have multiple very similar entities without special logic,
|
||||||
|
you could consider a lightweight generic interface/base; for now, the specialized service implementation is cleaner. */
|
||||||
|
|
||||||
public interface ICatalogService
|
public interface ICatalogService
|
||||||
{
|
{
|
||||||
Task<List<CatalogReadDto>> GetAllAsync(CancellationToken cancellationToken = default);
|
Task<List<CatalogReadDto>> GetAllAsync(CancellationToken cancellationToken = default);
|
||||||
|
|||||||
@@ -15,21 +15,6 @@ namespace DbFirst.Infrastructure.Repositories;
|
|||||||
|
|
||||||
// TODO: instead of creating implementation of repository per entity, consider using generic repository pattern (eg. Repository<T>) to reduce code duplication.
|
// TODO: instead of creating implementation of repository per entity, consider using generic repository pattern (eg. Repository<T>) to reduce code duplication.
|
||||||
|
|
||||||
/* Copilot's Response:
|
|
||||||
A generic CRUD base service adds little value in your case:
|
|
||||||
|
|
||||||
Pros:
|
|
||||||
• Less boilerplate for simple entities without special logic.
|
|
||||||
• Uniform CRUD signatures.
|
|
||||||
|
|
||||||
Cons/Practical here:
|
|
||||||
• Domain logic differs per entity(unique title check, setting audit fields, forbidding title changes, stored procs with output GUID).
|
|
||||||
• Generic services tend to be diluted by virtual methods/hooks for special cases—ending up with per-entity overrides and little real gain.
|
|
||||||
• With stored procedures and output parameters, the pattern doesn’t fit cleanly because operations aren’t symmetric (separate procs for insert/update/delete).
|
|
||||||
|
|
||||||
Conclusion: For this solution a generic service would be more overhead than benefit. If you later have multiple very similar entities without special logic,
|
|
||||||
you could consider a lightweight generic interface/base; for now, the specialized service implementation is cleaner. */
|
|
||||||
|
|
||||||
public class CatalogRepository : ICatalogRepository
|
public class CatalogRepository : ICatalogRepository
|
||||||
{
|
{
|
||||||
private readonly ApplicationDbContext _db;
|
private readonly ApplicationDbContext _db;
|
||||||
|
|||||||
Reference in New Issue
Block a user