diff --git a/DbFirst.API/Program.cs b/DbFirst.API/Program.cs index c406c41..07ce535 100644 --- a/DbFirst.API/Program.cs +++ b/DbFirst.API/Program.cs @@ -4,6 +4,8 @@ using DbFirst.Infrastructure; using DbFirst.Infrastructure.Repositories; using Microsoft.EntityFrameworkCore; +//TODO: create and add exception handling middleware + var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -11,6 +13,7 @@ builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); +// TODO: allow listed origins configured in appsettings.json builder.Services.AddCors(options => { options.AddDefaultPolicy(policy => @@ -21,9 +24,11 @@ builder.Services.AddCors(options => }); }); +// TODO: Create extension method for this in Infrastructure layer in case of using in multiple projects builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"))); +// TODO: Create extension method for this in Application layer in case of using in multiple projects builder.Services.AddAutoMapper(typeof(CatalogProfile).Assembly, typeof(ApplicationDbContext).Assembly); builder.Services.AddScoped(); diff --git a/DbFirst.Application/Catalogs/CatalogService.cs b/DbFirst.Application/Catalogs/CatalogService.cs index 755162d..98c3b49 100644 --- a/DbFirst.Application/Catalogs/CatalogService.cs +++ b/DbFirst.Application/Catalogs/CatalogService.cs @@ -4,6 +4,8 @@ using DbFirst.Domain.Entities; namespace DbFirst.Application.Catalogs; +//TODO: create generic service to reduce code duplication +//TODO: implement CQRS pattern with MediatR public class CatalogService : ICatalogService { private readonly ICatalogRepository _repository; diff --git a/DbFirst.Application/Catalogs/ICatalogService.cs b/DbFirst.Application/Catalogs/ICatalogService.cs index ba9dac6..d7fa862 100644 --- a/DbFirst.Application/Catalogs/ICatalogService.cs +++ b/DbFirst.Application/Catalogs/ICatalogService.cs @@ -1,5 +1,6 @@ namespace DbFirst.Application.Catalogs; +//TODO: create generic service to reduce code duplication public interface ICatalogService { Task> GetAllAsync(CancellationToken cancellationToken = default); diff --git a/DbFirst.Domain/Repositories/ICatalogRepository.cs b/DbFirst.Domain/Repositories/ICatalogRepository.cs index 6082ef7..85b1acd 100644 --- a/DbFirst.Domain/Repositories/ICatalogRepository.cs +++ b/DbFirst.Domain/Repositories/ICatalogRepository.cs @@ -2,6 +2,8 @@ using DbFirst.Domain.Entities; namespace DbFirst.Domain.Repositories; +// TODO: instead of creating interface per entity, consider using generic repository pattern (eg. IRepository) to reduce code duplication. +//TODO: move to application layer as a part of clean architecture public interface ICatalogRepository { Task> GetAllAsync(CancellationToken cancellationToken = default); diff --git a/DbFirst.Infrastructure/ApplicationDbContext.cs b/DbFirst.Infrastructure/ApplicationDbContext.cs index e8825bb..278a43c 100644 --- a/DbFirst.Infrastructure/ApplicationDbContext.cs +++ b/DbFirst.Infrastructure/ApplicationDbContext.cs @@ -12,6 +12,7 @@ public partial class ApplicationDbContext : DbContext public virtual DbSet VwmyCatalogs { get; set; } + // TODO: Configure column names on appsettings via IConfiguration protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => diff --git a/DbFirst.Infrastructure/Repositories/CatalogRepository.cs b/DbFirst.Infrastructure/Repositories/CatalogRepository.cs index beffe78..b37af01 100644 --- a/DbFirst.Infrastructure/Repositories/CatalogRepository.cs +++ b/DbFirst.Infrastructure/Repositories/CatalogRepository.cs @@ -6,6 +6,7 @@ using System.Data; namespace DbFirst.Infrastructure.Repositories; +// TODO: instead of creating implementation of repository per entity, consider using generic repository pattern (eg. Repository) to reduce code duplication. public class CatalogRepository : ICatalogRepository { private readonly ApplicationDbContext _db;