Move repository interfaces to Application layer
Refactored IRepository<T> and ICatalogRepository to reside in the DbFirst.Application layer instead of Domain. Updated namespaces, using statements, and all references in services and handlers. Adjusted csproj dependencies to reflect the new structure. Updated comments to clarify Clean Architecture rationale and improved separation of concerns.
This commit is contained in:
@@ -1,38 +1,14 @@
|
||||
using AutoMapper;
|
||||
using DbFirst.Domain.Repositories;
|
||||
using DbFirst.Application.Repositories;
|
||||
using DbFirst.Domain.Entities;
|
||||
using DbFirst.Domain;
|
||||
|
||||
namespace DbFirst.Application.Catalogs;
|
||||
|
||||
//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. */
|
||||
|
||||
/* Hakan's Response:
|
||||
* No, it absolutely makes sense to create a generic service using Options pattern. So, you can easily inject your SQL queries or stored procedure names via configuration.
|
||||
* see: https://docs.microsoft.com/en-us/dotnet/core/extensions/options
|
||||
*/
|
||||
|
||||
//TODO (TR): kod tekrar?n? azaltmak için generic bir servis/basit CRUD altyap?s? ekleyin
|
||||
//TODO: implement CQRS pattern with MediatR
|
||||
|
||||
/* Hakan's response
|
||||
* Here is the main part. We dont even need a service layer if we implement CQRS with MediatR at least for CRUD operations.
|
||||
*/
|
||||
|
||||
//TODO (TR): CQRS desenini MediatR ile uygulay?n
|
||||
public class CatalogService : ICatalogService
|
||||
{
|
||||
private readonly ICatalogRepository _repository;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using AutoMapper;
|
||||
using DbFirst.Application.Repositories;
|
||||
using DbFirst.Domain.Entities;
|
||||
using DbFirst.Domain.Repositories;
|
||||
using MediatR;
|
||||
|
||||
namespace DbFirst.Application.Catalogs.Commands;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using DbFirst.Domain.Repositories;
|
||||
using DbFirst.Application.Repositories;
|
||||
using MediatR;
|
||||
|
||||
namespace DbFirst.Application.Catalogs.Commands;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using AutoMapper;
|
||||
using DbFirst.Application.Repositories;
|
||||
using DbFirst.Domain.Entities;
|
||||
using DbFirst.Domain.Repositories;
|
||||
using DbFirst.Domain;
|
||||
using MediatR;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using AutoMapper;
|
||||
using DbFirst.Domain.Repositories;
|
||||
using DbFirst.Application.Repositories;
|
||||
using MediatR;
|
||||
|
||||
namespace DbFirst.Application.Catalogs.Queries;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using AutoMapper;
|
||||
using DbFirst.Domain.Repositories;
|
||||
using DbFirst.Application.Repositories;
|
||||
using MediatR;
|
||||
|
||||
namespace DbFirst.Application.Catalogs.Queries;
|
||||
|
||||
10
DbFirst.Application/Repositories/ICatalogRepository.cs
Normal file
10
DbFirst.Application/Repositories/ICatalogRepository.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using DbFirst.Domain;
|
||||
using DbFirst.Domain.Entities;
|
||||
|
||||
namespace DbFirst.Application.Repositories;
|
||||
|
||||
public interface ICatalogRepository : IRepository<VwmyCatalog>
|
||||
{
|
||||
Task<VwmyCatalog?> GetByTitleAsync(string title, CancellationToken cancellationToken = default);
|
||||
Task<VwmyCatalog?> UpdateAsync(int id, VwmyCatalog catalog, CatalogUpdateProcedure procedure, CancellationToken cancellationToken = default);
|
||||
}
|
||||
10
DbFirst.Application/Repositories/IRepository.cs
Normal file
10
DbFirst.Application/Repositories/IRepository.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace DbFirst.Application.Repositories;
|
||||
|
||||
public interface IRepository<T>
|
||||
{
|
||||
Task<List<T>> GetAllAsync(CancellationToken cancellationToken = default);
|
||||
Task<T?> GetByIdAsync(int id, CancellationToken cancellationToken = default);
|
||||
Task<T> InsertAsync(T entity, CancellationToken cancellationToken = default);
|
||||
Task<T?> UpdateAsync(int id, T entity, CancellationToken cancellationToken = default);
|
||||
Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default);
|
||||
}
|
||||
Reference in New Issue
Block a user