I am trying to review our current architecture. These are the current layers, trying to analyze them, and see if the following three ideas are good practice.

DatabaseSQLStorage ---> Entity Framework Class Layer ----> Generic Repository ---> Entity Framework Copy Model Layer ----> Application Service ---> DTO Layer ----> API Controller

1) One thing I am concerned, the Application layer has tangible method references to Two layers. so if the entity layer breaks, Two layers actually break (Entity and the Copy Model Layer). The Repository should only bring Model layer, and we should Only be working with that at that point, not having two references.

When discussing with architect, he mentioned 'well we have differential functional areas with our 5 application services, so not sure. Was trying to comprehend this.

public async Task<ProductDto> GetProductById(int id)
    var productData = await IProductRepository.GetAsync(id);
    ProductModel productModel = mapper.Map<productModel>(productData);
    var productDto = mapper.Map<ProductModel, ProductDto>(departmentModel);
    return productDto;

2) Another thing I am questioning is, we have both a Model Layer, AND a DTO Layer. The Model layer, contains computed members, see Article below. We are not doing Domain Driven Design (no aggregate roots, value objects, clusters, etc)

ProductFullName => ProductType + LastName + ProductDescription // Concatenation
AccountValue => Quantity * ProductCost

Copy Database Entities into Another Layer in Software Architecture?

I am fine with DTO Layer, for example, the business contains private account numbers, Social Security, birthdate, etc, that we remove before sending APIs

Just concerned if a DTO layer is needed with the other copy layer.

3) Also, not a fan of the generic repository, since EF DbContext is a Repository and Unit of Work by itself, but that's another point too .

  • 1
  • agreed, first question was whether we need a Model layer which I agree, now question is, do we need Two model layers – user354368 Jan 7 '20 at 19:22
  • Sure, I have followed you at this path, and it gives some additional background information. Just saying, nothing wrong so far IMO. – πάντα ῥεῖ Jan 7 '20 at 19:23
  • 1
    What are your goals for the redesign? – Robert Harvey Jan 7 '20 at 19:58
  • 1
    There are more patterns available than one can follow, and a lot of them are mutually exclusive. Most designs have a few patterns that are really essential for them to work well, and a few more to ensure they are long term viable. For example, testability pivots on using the repository pattern correctly in your example. We don't know enough about the properties of your project and its design goals to make any more specific recommendations. – Martin K Jan 7 '20 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy