avatar
ddd

Domain Driven Desig Temelleri - Repositories

Domain Driven Desig Temelleri - Repositories
serkan
3 min read
#ddd

Giriş

Repository Ler ile Çalışmak

Persistence Ignorance: Business objects have no logic related to how data is stored and retrieved. faydalari: providers common abstraction for persistence promotes separation of concerns Communicates design decisions Enables testabliity Imporved maintanablity Tavsiyeler Think of it as an in memory collection Implemented a known common access Interface Include methods to add & remove Cusom Query Implementation usin EF Core Get a Client with theri Pations Use repositories for aggregate roots only Client focuses on model repository on persistence Common Problems:

N+1 Query Errors Inappropriate use of wafer or lazy loading. Fetching more data than required. Database profiling Can surface many problems Databse IDE profilers Code-based profiling or logging 3th party PRofilers

Should repositoryier return IQueryable? Pek cok yararinin yaninda oldukca da sakincali durumlari var.

Accept Arbitrary Predicates (instead of returning IQueryable from Repository List methods)

Predicate Expression used in the search condition of a query’s where clouse. Generic Repository Benefits Spesification Pattern

Spesification are used to specify the satte of an object, and as such, are primarily used in there ways

Validation Selection & Querying Creation for a specific purpose. Create explicit predicate-like Value Objects for specialized purposes. A Specification is a predicate that determines if an object satisfies some criteria.

A Basic Specification bool IsStaisfiedBy(object someObjkect)

Combining Specifications with ORMs Benefists:

  1. Named Classes via Ubiquitous Languagg
  2. Reusable
  3. Separate Persistence from Domain Model and UI Keep Business Logic out of the persistence Layer and Database Help Entities & Aggregates follow the Single Responsibility Principle Implementation Specification Classes You will need to write the rules of your specifications The classes belong in your domain model If only a few, organize them them in root Specifications folder. Or, alongsideyour aggregates in theri folders. The specificationtion can be easily test in isolation.

Repository: A class encapsulates the data persistence for an aggregate root Specification Pattern. A method of encapsulating a business rule so that it can be passed to other methods which are responsible for applying it. Persistence Ignorance: objects are unaware of where their data comes from or goes to ACIS: Atomic, Consistent, Isolated, and Durable

Sonuc

DDD bize rehberlik saglar, keskin degismez kurallar degil. BUrda mükemmeliyetci olmak bizi bazen gereksiz yere isimizden ali koyabilir. Hic bir model mükemmel degildir. Burda ki asil amacimiz problemimizi cözecek bir yazilimi yapmamizi saglayan, ele aldigimiz senaryolari ihtiva eden bir model ortaya koymak. Hepsi bu. Tüm modeller yanlistir, bazi modeller kullanislidir. Modelimiz mükemmel olmaaz, sadece ele aldigimiz problemi cözecek bir yazilim yapmamizi saglasin yeter ve kullanan insanlari mutlu etmesi kafidir.

Etki alanı modelimizin mükemmel olması gerekmez. Sadece insanların sorunları çözmelerine ve işlerini yapmalarına yardımcı olan yazılımı geliştirmemize yardım etmeleri gerekiyor.

Mükemmel olani yapmaya calismamaliyiz, kullanisli olani yapmaya calissak yeterlidir.