Clean Architecture

다음 두 강좌면 대충 끝나는듯.

uncle bob martin

  • The Web is a Delivery Mechanism
  • Database is Detail
  • A good architecture allows major decisions to be deferred

Clean Architecture with ASP.NET Core 2.1

정리

  • Domain Layer
    • Entities
    • Value
    • Objects
    • Enumerations (꼭 생성자에서 초기화를 하자)
    • Logic
    • Exceptions
  • Application Layer
    • Interfaces
    • Models
    • Logic
    • Commands / Queries
    • Validators
    • Exceptions
  • Persistence Layer
    • DbContext
    • Migrations
    • Configurations
    • Seeding
    • Abstractions
  • Infrastructure Layer
    • Implementations, e.g.
    • API Clients
    • File System
    • Email / SMS System
    • Clock
    • Anything external
  • Presentation Layer
    • SPA – Angular or React
    • Web API
    • Razor
    • Pages
    • MVC
    • Web Forms

내 노트

MediatR

신의 한수인듯 싶다. https://github.com/jbogard/MediatR

밥 아저씨의 request model과 response model을 한방에 해결해준다.

궁금햇던것은 두번째 비디오에서 automapper를 사용하지 않는것이엿다. MediatR를 만든 사람이 authmapper를 만들었는데 왜 사용하지 않을가? 쓰면 편한데. 라는 궁금증이 아직도 있다.

샘플 코드에서는 automapper를 사용하지 않고 다음처럼 처리햇다.

namespace Northwind.Application.Categories.Models
{
    public class ProductPreviewDto
    {
        public int ProductId { get; set; }

        public string ProductName { get; set; }

        public decimal? UnitPrice { get; set; }

        public static Expression<Func<Product, ProductPreviewDto>> Projection
        {
            get
            {
                return p => new ProductPreviewDto
                {
                    ProductId = p.ProductId,
                    ProductName = p.ProductName,
                    UnitPrice = p.UnitPrice
                };
            }
        }
        public static ProductPreviewDto Create(Product product)
        {
          return Projection.Compile().Invoke(product);
        }
    }
}

사용은

var renderer = ProductPreviewDto.Create(entity);

이러면 매핑이 되서 나온다.

Automapper를 왜 안쓴느지는 더 확인이 필요. 아래 링크에서보면 코드가 완전 간단해지는것을 알수 있다. 나도 써야겟다.

infrastructure에 INotificationService

이것이 어떻게 동작하는지 궁금햇다. 확인해보니 application layer에 interface를 만들고 application은 이 인터페이스로만 코딩을 한다.

infrastructure에서 이 인터페이스를 구현해서 클래스로 만든다.

나중에 이걸 di해주면 잘 동작한다.

automapper 적용

  • 확인해보니 최신코드는 automapper는 들어가 있는것도 같다. ==> 적용 완료

궁금증

  • authmapper를 왜 안쓰는가?
  • 인증은 webapi단에서 하는가? 아니면 application layer에서 해야하는것인가?
  • 페이징은 webapi단에서 하는가? 아니면 application layer에서 해야하는것인가?
  • ddd에서 entity와 vo의 차이는 무엇인가?(immutable)?
teamsmiley's profile image

teamsmiley

2019-02-02 00:00

Read more posts by this author