SlideShare una empresa de Scribd logo
1 de 28
Descargar para leer sin conexión
EFFECTIVE
DOMAIN DRIVEN DESIGN
Oğuzhan Soykan
WHO AM I?
oguzsoykan
osoykan
LET’S GET STARTED
WHY?
DOMAIN DRIVEN DESIGN
THE NEED OF DDD
▸ What is DDD?
▸ Learning existing domain as daily language
▸ Implementing business requirements effectively, we are business devs
eventually(?)
▸ Improving the communication between teams and domain experts
▸ Everyone has no same way to learn new things in the business (shapes,
visualized things, speaking, documentation)
DOMAIN DRIVEN DESIGN
DESIGN PROBLEMS
▸ Devs wrapped up too much technology
▸ The Database is given too much priority
One-To-Many, Zero-To-One, ForeignKey, NotNull, Where is my Join?
▸ Poor collaboration
Not focusing business complexity, struggling with tech side, not talking with
Domain Experts
▸ Hidden business or leaked business to UI
UtilityHelpers, Providers, BullshitManagers!
▸ Task board shuffling rather than thoughtful design
DOMAIN DRIVEN DESIGN
Problems
Competitive
Advantage
Complexity
Accounting(Internal) S L
Banner L S
Product L L
HOW TO DECIDE DDD?
DOMAIN DRIVEN DESIGN
HOW TO DESIGN?
STRATEGIC DESIGN TACTICAL DESIGN
Bounded Context
Ubiquitous Language
AggregateRoot
Entity
Value Objects
Domain Events
DOMAIN DRIVEN DESIGN
UBIQUITOUS LANGUAGE
DOMAIN DRIVEN DESIGN
WHAT ABOUT EFFECTIVENESS ?
▸ Anemic Domain Model
▸ Transaction script
▸ Mixing Read-Write
▸ Microservices?
▸ Modelling
▸ What about performance ?
▸ Coupled Services
Command —> Domain —> Rest(Another) —//—> Save
‣ The thought of changing the ORM, repository abstractions
USE AGGREGATE
PATTERN EFFECTIVELY
ANEMIC DOMAIN
MODEL
ANEMIC DOMAIN MODEL
public class Product : AggregateRoot
{
public ICollection<ProductContent> Contents;
protected Product()
{
Register<Events.ContentAddedToProduct>(When);
}
}
ANEMIC DOMAIN MODEL
public class ProductCommandHandler : IHandles<AddContentToProductCommand>
{
public Task Handle(AddContentToProductCommand command)
{
if(_productRepository.Exists(command.ProductId))
{
if(command.ColorCode.Lenght > 50)
{
throw new BusinessException("ColorCode can not be greater than 50");
}
Product aggregate = _productRepository.Get(command.ProductId);
if(aggregate == null)
{
throw new AggregateNotFoundException(command.ProductId);
}
ProductContent productContent = _productContentRepository
.GetByCodeAndProductId(command.ColorCode, command.ProductId);
if(productContent != null)
{
throw new BusinessException($"Content already added {command.ColorCode}");
}
aggregate.Contents.Add(new ProductContent(aggregate, command.ColorCode));
_productRepository.Save(aggregate);
}
}
}
ANEMIC DOMAIN MODEL
public class ProductCommandHandler : IHandles<AddContentToProductCommand>
{
public Task Handle(AddContentToProductCommand command)
{
_productRepository
.Get(command.ProductId)
.Match(
product => product.AddContent(command.ColorCode),
() => throw new AggregateNotFoundException(command.ProductId);
);
}
}
▸
ANEMIC DOMAIN MODEL
public class Product : AggregateRoot
{
public ICollection<ProductContent> Contents;
protected Product()
{
Register<Events.ContentAddedToProduct>(When);
}
public void AddContent(string colorCode)
{
if(colorCode.Lenght > 50)
{
throw new BusinessException("ColorCode can not be greater than 50");
}
if(Contents.Any(x => x.ColorCode == colorCode))
{
throw new BusinessException($"Content already added {colorCode}");
}
ApplyChange(
new Events.ContentAddedToProduct(this.Id, colorCode);
)
}
private void When(Events.ContentAddedToProduct @event)
{
Contents.Add(new ProductContent(this, @event.ColorCode));
}
}
BOUNDED CONTEXT
PER MICRO SERVICE
MICROSERVICES
BOUNDED CONTEXT PER MICRO-SERVICE
BOUNDED CONTEXT PER MICRO-SERVICE
IMPEDANCE
MISMATCH & CQRS
WHAT ABOUT
PERFORMANCE ?
IMPEDANCE MISMATCH & CQRS
Set(x => x.Products, c =>
{
c.Fetch(CollectionFetchMode.Join);
c.BatchSize(100);
c.Lazy(CollectionLazy.Lazy);
c.Access(Accessor.Field);
c.Sort<CustomComparer>();
c.Type<CustomType>();
c.Persister<CustomPersister>();
c.OptimisticLock(true);
c.Mutable(true);
c.Cache(x =>
{
x.Include(CacheInclude.All);
x.Usage(CacheUsage.ReadOnly);
x.Region("regionName");
});
c.SqlDelete("SQL command");
c.SqlDeleteAll("SQL command");
c.SqlInsert("SQL command");
c.SqlUpdate("SQL command");
c.Subselect("SQL command");
c.Loader("loaderRef");
}, r =>
{
r.Element(e => { });
r.Component(c => { });
r.OneToMany(o => { });
r.ManyToMany(m => { });
r.ManyToAny<IAnyType>(m => { });
});
c.Table("tableName");
c.Schema("schemaName");
c.Catalog("catalogName");
c.Cascade(Cascade.All);
c.Inverse(true);
c.Where("SQL command");
c.Filter("filterName", f => f.Condition("condition"));
c.OrderBy(x => x.Name); // or SQL expression
c.Key(k =>
{
k.Column("columnName");
k.Column(x =>
{
x.Name("columnName");
});
k.ForeignKey("collection_fk");
k.NotNullable(true);
k.OnDelete(OnDeleteAction.NoAction);
k.PropertyRef(x => x.Name);
k.Unique(true);
k.Update(true);
});
IMPEDANCE MISMATCH & CQRS
DTO
PURE SQL
User Inputs
Transactional ORM Session
DOMAIN EVENTS
(LOOSELY) COUPLED
SERVICES
DOMAIN EVENTS
public class Product : AggregateRoot
{
public ICollection<ProductContent> Contents;
protected Product()
{
Register<Events.ContentAddedToProduct>(When);
}
}
public abstract class AggregateRoot
{
private ICollection<object> _events;
private Dictionary<Type, Action<object>> _routes;
void Register<TEvent>(Action<TEvent> route)
{
_routes.Add(typeof(TEvent), route);
}
void ApplyChange(object @event)
{
_routes[@event.GetType()].Invoke(@event);
}
public ICollection<object> GetChanges()
{
return _events;
}
}
ENTITY FRAMEWORK & EVENT PUBLISHING
Func<Task> PrepareCompleteAction(TDbContext dbContext)
{
if (dbContext.ChangeTracker.HasChanges())
{
List<EntityEntry> changes = dbContext.ChangeTracker.Entries().ToList();
IEnumerable<AggregateRoot> trackedChanges = changes.Where(x => x.Entity is AggregateRoot)
.Select(x => (AggregateRoot)x.Entity);
return async () =>
{
List<Event> events = trackedChanges.SelectMany(x => x.GetChanges()).OfType<Event>().ToList();
foreach (Event @event in events)
{
await _publisher.Publish(@event);
}
};
}
return () => Task.CompletedTask;
}
NHIBERNATE & EVENT PUBLISHING
public class NHibernateInterceptor : EmptyInterceptor
{
private readonly IMediator _mediator;
public override void PostFlush(ICollection entities)
{
var changes = entities.OfType<object>().Where(e => e is AggregateRoot);
foreach (var entity in changes)
{
TriggerDomainEvents(entity);
}
base.PostFlush(entities);
}
protected virtual void TriggerDomainEvents(object entity)
{
var aggregateChangeTracker = (AggregateRoot) entity;
if (!aggregateChangeTracker.GetChanges().Any())
{
return;
}
var domainEvents = aggregateChangeTracker.GetChanges().ToList();
aggregateChangeTracker.ClearChanges();
foreach (var @event in domainEvents)
{
_mediator.Publish((INotification) @event);
}
}
}
REALLY?
CHANGING THE O/RM
USE EVENT
STORMING
MODELLING
https://webeventstorming.com
THANKS
Oğuzhan Soykan

Más contenido relacionado

La actualidad más candente

ドメイン駆動設計再入門
ドメイン駆動設計再入門ドメイン駆動設計再入門
ドメイン駆動設計再入門Yukei Wachi
 
Swot anali̇zi̇
Swot anali̇zi̇Swot anali̇zi̇
Swot anali̇zi̇Esra Çimen
 
ドメイン駆動設計 コアドメインを語り合ってみよう
ドメイン駆動設計 コアドメインを語り合ってみようドメイン駆動設計 コアドメインを語り合ってみよう
ドメイン駆動設計 コアドメインを語り合ってみよう増田 亨
 
DDDはオブジェクト指向を利用してどのようにメンテナブルなコードを書くか
DDDはオブジェクト指向を利用してどのようにメンテナブルなコードを書くかDDDはオブジェクト指向を利用してどのようにメンテナブルなコードを書くか
DDDはオブジェクト指向を利用してどのようにメンテナブルなコードを書くかKoichiro Matsuoka
 
DDDのモデリングとは何なのか、 そしてどうコードに落とすのか
DDDのモデリングとは何なのか、 そしてどうコードに落とすのかDDDのモデリングとは何なのか、 そしてどうコードに落とすのか
DDDのモデリングとは何なのか、 そしてどうコードに落とすのかKoichiro Matsuoka
 
Swot anali̇z1
Swot anali̇z1Swot anali̇z1
Swot anali̇z1bayanfil8
 
ちいさなオブジェクトでドメインモデルを組み立てる
ちいさなオブジェクトでドメインモデルを組み立てるちいさなオブジェクトでドメインモデルを組み立てる
ちいさなオブジェクトでドメインモデルを組み立てる増田 亨
 
ドメイン駆動設計 分析しながら設計する
ドメイン駆動設計 分析しながら設計するドメイン駆動設計 分析しながら設計する
ドメイン駆動設計 分析しながら設計する増田 亨
 
私がドメイン駆動設計をやる理由
私がドメイン駆動設計をやる理由私がドメイン駆動設計をやる理由
私がドメイン駆動設計をやる理由増田 亨
 
ドメイン駆動設計に15年取り組んでわかったこと
ドメイン駆動設計に15年取り組んでわかったことドメイン駆動設計に15年取り組んでわかったこと
ドメイン駆動設計に15年取り組んでわかったこと増田 亨
 
「実践ドメイン駆動設計」社内読書会まとめ ~IDDD本難民に捧げる1章から7章~
「実践ドメイン駆動設計」社内読書会まとめ ~IDDD本難民に捧げる1章から7章~「実践ドメイン駆動設計」社内読書会まとめ ~IDDD本難民に捧げる1章から7章~
「実践ドメイン駆動設計」社内読書会まとめ ~IDDD本難民に捧げる1章から7章~A AOKI
 
Go Programlama Dili - Seminer
Go Programlama Dili - SeminerGo Programlama Dili - Seminer
Go Programlama Dili - SeminerCihan Özhan
 
ドメイン駆動設計 失敗したことと成功したこと
ドメイン駆動設計 失敗したことと成功したことドメイン駆動設計 失敗したことと成功したこと
ドメイン駆動設計 失敗したことと成功したことBIGLOBE Inc.
 
アジャイルによくきく?モデリング
アジャイルによくきく?モデリングアジャイルによくきく?モデリング
アジャイルによくきく?モデリングIwao Harada
 
ドメイン駆動設計という設計スタイル
ドメイン駆動設計という設計スタイルドメイン駆動設計という設計スタイル
ドメイン駆動設計という設計スタイル増田 亨
 
DDDをScrumで廻す あるいは ScrumをDDDで廻す
DDDをScrumで廻す あるいは ScrumをDDDで廻す DDDをScrumで廻す あるいは ScrumをDDDで廻す
DDDをScrumで廻す あるいは ScrumをDDDで廻す Kiro Harada
 
強いて言えば「集約どう実装するのかな、を考える」な話
強いて言えば「集約どう実装するのかな、を考える」な話強いて言えば「集約どう実装するのかな、を考える」な話
強いて言えば「集約どう実装するのかな、を考える」な話Yoshitaka Kawashima
 
なぜ私はこの本を書いたか
なぜ私はこの本を書いたかなぜ私はこの本を書いたか
なぜ私はこの本を書いたかSatoru Ueda
 

La actualidad más candente (20)

ドメイン駆動設計再入門
ドメイン駆動設計再入門ドメイン駆動設計再入門
ドメイン駆動設計再入門
 
Swot anali̇zi̇
Swot anali̇zi̇Swot anali̇zi̇
Swot anali̇zi̇
 
ドメイン駆動設計 コアドメインを語り合ってみよう
ドメイン駆動設計 コアドメインを語り合ってみようドメイン駆動設計 コアドメインを語り合ってみよう
ドメイン駆動設計 コアドメインを語り合ってみよう
 
DDDはオブジェクト指向を利用してどのようにメンテナブルなコードを書くか
DDDはオブジェクト指向を利用してどのようにメンテナブルなコードを書くかDDDはオブジェクト指向を利用してどのようにメンテナブルなコードを書くか
DDDはオブジェクト指向を利用してどのようにメンテナブルなコードを書くか
 
DDDのモデリングとは何なのか、 そしてどうコードに落とすのか
DDDのモデリングとは何なのか、 そしてどうコードに落とすのかDDDのモデリングとは何なのか、 そしてどうコードに落とすのか
DDDのモデリングとは何なのか、 そしてどうコードに落とすのか
 
Swot anali̇z1
Swot anali̇z1Swot anali̇z1
Swot anali̇z1
 
ちいさなオブジェクトでドメインモデルを組み立てる
ちいさなオブジェクトでドメインモデルを組み立てるちいさなオブジェクトでドメインモデルを組み立てる
ちいさなオブジェクトでドメインモデルを組み立てる
 
ドメイン駆動設計 分析しながら設計する
ドメイン駆動設計 分析しながら設計するドメイン駆動設計 分析しながら設計する
ドメイン駆動設計 分析しながら設計する
 
私がドメイン駆動設計をやる理由
私がドメイン駆動設計をやる理由私がドメイン駆動設計をやる理由
私がドメイン駆動設計をやる理由
 
ドメイン駆動設計に15年取り組んでわかったこと
ドメイン駆動設計に15年取り組んでわかったことドメイン駆動設計に15年取り組んでわかったこと
ドメイン駆動設計に15年取り組んでわかったこと
 
「実践ドメイン駆動設計」社内読書会まとめ ~IDDD本難民に捧げる1章から7章~
「実践ドメイン駆動設計」社内読書会まとめ ~IDDD本難民に捧げる1章から7章~「実践ドメイン駆動設計」社内読書会まとめ ~IDDD本難民に捧げる1章から7章~
「実践ドメイン駆動設計」社内読書会まとめ ~IDDD本難民に捧げる1章から7章~
 
Go Programlama Dili - Seminer
Go Programlama Dili - SeminerGo Programlama Dili - Seminer
Go Programlama Dili - Seminer
 
ドメイン駆動設計 失敗したことと成功したこと
ドメイン駆動設計 失敗したことと成功したことドメイン駆動設計 失敗したことと成功したこと
ドメイン駆動設計 失敗したことと成功したこと
 
アジャイルによくきく?モデリング
アジャイルによくきく?モデリングアジャイルによくきく?モデリング
アジャイルによくきく?モデリング
 
ドメイン駆動設計という設計スタイル
ドメイン駆動設計という設計スタイルドメイン駆動設計という設計スタイル
ドメイン駆動設計という設計スタイル
 
Flutter for tche linux
Flutter for tche linuxFlutter for tche linux
Flutter for tche linux
 
DDDをScrumで廻す あるいは ScrumをDDDで廻す
DDDをScrumで廻す あるいは ScrumをDDDで廻す DDDをScrumで廻す あるいは ScrumをDDDで廻す
DDDをScrumで廻す あるいは ScrumをDDDで廻す
 
強いて言えば「集約どう実装するのかな、を考える」な話
強いて言えば「集約どう実装するのかな、を考える」な話強いて言えば「集約どう実装するのかな、を考える」な話
強いて言えば「集約どう実装するのかな、を考える」な話
 
Pest analizi
Pest analiziPest analizi
Pest analizi
 
なぜ私はこの本を書いたか
なぜ私はこの本を書いたかなぜ私はこの本を書いたか
なぜ私はこの本を書いたか
 

Similar a Domain Driven Design - Developer Summit Turkey

Design patterns for fun and profit
Design patterns for fun and profitDesign patterns for fun and profit
Design patterns for fun and profitNikolas Vourlakis
 
Baby steps to Domain-Driven Design
Baby steps to Domain-Driven DesignBaby steps to Domain-Driven Design
Baby steps to Domain-Driven DesignŽilvinas Kuusas
 
Fast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDBFast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDBMongoDB
 
Deployment Driven Development and Performance Testing TEFCON2015
Deployment Driven Development and Performance Testing TEFCON2015Deployment Driven Development and Performance Testing TEFCON2015
Deployment Driven Development and Performance Testing TEFCON2015Almudena Vivanco
 
Practicing Red, Green, Refactor!
Practicing Red, Green, Refactor!Practicing Red, Green, Refactor!
Practicing Red, Green, Refactor!XPDays
 
DevDay2017 ESGI Essential DDD
DevDay2017 ESGI Essential DDDDevDay2017 ESGI Essential DDD
DevDay2017 ESGI Essential DDDGregory Boissinot
 
PixelsCamp | Odoo - The Open Source Business Apps Platform for the 21st Century
PixelsCamp | Odoo - The Open Source Business Apps Platform for the 21st CenturyPixelsCamp | Odoo - The Open Source Business Apps Platform for the 21st Century
PixelsCamp | Odoo - The Open Source Business Apps Platform for the 21st CenturyDaniel Reis
 
ITB2017 - Intro to Behavior Driven Development
ITB2017 - Intro to Behavior Driven DevelopmentITB2017 - Intro to Behavior Driven Development
ITB2017 - Intro to Behavior Driven DevelopmentOrtus Solutions, Corp
 
Image archive, analysis & report generation with Google Cloud
Image archive, analysis & report generation with Google CloudImage archive, analysis & report generation with Google Cloud
Image archive, analysis & report generation with Google Cloudwesley chun
 
Iddd domain service
Iddd domain serviceIddd domain service
Iddd domain serviceEric Huang
 
Compiler Case Study - Design Patterns in C#
Compiler Case Study - Design Patterns in C#Compiler Case Study - Design Patterns in C#
Compiler Case Study - Design Patterns in C#CodeOps Technologies LLP
 
A (very) opinionated guide to MSBuild and Project Files
A (very) opinionated guide to MSBuild and Project FilesA (very) opinionated guide to MSBuild and Project Files
A (very) opinionated guide to MSBuild and Project FilesDavid Wengier
 
Introduction to interactive data visualisation using R Shiny
Introduction to interactive data visualisation using R ShinyIntroduction to interactive data visualisation using R Shiny
Introduction to interactive data visualisation using R Shinyanamarisaguedes
 
Event Storming #10 DDDGreece
Event Storming #10 DDDGreeceEvent Storming #10 DDDGreece
Event Storming #10 DDDGreeceAntonios Klimis
 
Tips for Building your First XPages Java Application
Tips for Building your First XPages Java ApplicationTips for Building your First XPages Java Application
Tips for Building your First XPages Java ApplicationTeamstudio
 

Similar a Domain Driven Design - Developer Summit Turkey (20)

Design patterns for fun and profit
Design patterns for fun and profitDesign patterns for fun and profit
Design patterns for fun and profit
 
Baby steps to Domain-Driven Design
Baby steps to Domain-Driven DesignBaby steps to Domain-Driven Design
Baby steps to Domain-Driven Design
 
Fast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDBFast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDB
 
Deployment Driven Development and Performance Testing TEFCON2015
Deployment Driven Development and Performance Testing TEFCON2015Deployment Driven Development and Performance Testing TEFCON2015
Deployment Driven Development and Performance Testing TEFCON2015
 
Practicing Red, Green, Refactor!
Practicing Red, Green, Refactor!Practicing Red, Green, Refactor!
Practicing Red, Green, Refactor!
 
DevDay2017 ESGI Essential DDD
DevDay2017 ESGI Essential DDDDevDay2017 ESGI Essential DDD
DevDay2017 ESGI Essential DDD
 
PixelsCamp | Odoo - The Open Source Business Apps Platform for the 21st Century
PixelsCamp | Odoo - The Open Source Business Apps Platform for the 21st CenturyPixelsCamp | Odoo - The Open Source Business Apps Platform for the 21st Century
PixelsCamp | Odoo - The Open Source Business Apps Platform for the 21st Century
 
ITB2017 - Intro to Behavior Driven Development
ITB2017 - Intro to Behavior Driven DevelopmentITB2017 - Intro to Behavior Driven Development
ITB2017 - Intro to Behavior Driven Development
 
Bdd spex
Bdd spexBdd spex
Bdd spex
 
L04 Software Design Examples
L04 Software Design ExamplesL04 Software Design Examples
L04 Software Design Examples
 
Image archive, analysis & report generation with Google Cloud
Image archive, analysis & report generation with Google CloudImage archive, analysis & report generation with Google Cloud
Image archive, analysis & report generation with Google Cloud
 
Extending Twig
Extending TwigExtending Twig
Extending Twig
 
Iddd domain service
Iddd domain serviceIddd domain service
Iddd domain service
 
Beyond usability
Beyond usabilityBeyond usability
Beyond usability
 
Compiler Case Study - Design Patterns in C#
Compiler Case Study - Design Patterns in C#Compiler Case Study - Design Patterns in C#
Compiler Case Study - Design Patterns in C#
 
A (very) opinionated guide to MSBuild and Project Files
A (very) opinionated guide to MSBuild and Project FilesA (very) opinionated guide to MSBuild and Project Files
A (very) opinionated guide to MSBuild and Project Files
 
Introduction to interactive data visualisation using R Shiny
Introduction to interactive data visualisation using R ShinyIntroduction to interactive data visualisation using R Shiny
Introduction to interactive data visualisation using R Shiny
 
Event Storming #10 DDDGreece
Event Storming #10 DDDGreeceEvent Storming #10 DDDGreece
Event Storming #10 DDDGreece
 
Tips for Building your First XPages Java Application
Tips for Building your First XPages Java ApplicationTips for Building your First XPages Java Application
Tips for Building your First XPages Java Application
 
Facade Design Pattern
Facade Design PatternFacade Design Pattern
Facade Design Pattern
 

Último

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456KiaraTiradoMicha
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 

Último (20)

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 

Domain Driven Design - Developer Summit Turkey

  • 4. DOMAIN DRIVEN DESIGN THE NEED OF DDD ▸ What is DDD? ▸ Learning existing domain as daily language ▸ Implementing business requirements effectively, we are business devs eventually(?) ▸ Improving the communication between teams and domain experts ▸ Everyone has no same way to learn new things in the business (shapes, visualized things, speaking, documentation)
  • 5. DOMAIN DRIVEN DESIGN DESIGN PROBLEMS ▸ Devs wrapped up too much technology ▸ The Database is given too much priority One-To-Many, Zero-To-One, ForeignKey, NotNull, Where is my Join? ▸ Poor collaboration Not focusing business complexity, struggling with tech side, not talking with Domain Experts ▸ Hidden business or leaked business to UI UtilityHelpers, Providers, BullshitManagers! ▸ Task board shuffling rather than thoughtful design
  • 7. DOMAIN DRIVEN DESIGN HOW TO DESIGN? STRATEGIC DESIGN TACTICAL DESIGN Bounded Context Ubiquitous Language AggregateRoot Entity Value Objects Domain Events
  • 9. DOMAIN DRIVEN DESIGN WHAT ABOUT EFFECTIVENESS ? ▸ Anemic Domain Model ▸ Transaction script ▸ Mixing Read-Write ▸ Microservices? ▸ Modelling ▸ What about performance ? ▸ Coupled Services Command —> Domain —> Rest(Another) —//—> Save ‣ The thought of changing the ORM, repository abstractions
  • 11. ANEMIC DOMAIN MODEL public class Product : AggregateRoot { public ICollection<ProductContent> Contents; protected Product() { Register<Events.ContentAddedToProduct>(When); } }
  • 12. ANEMIC DOMAIN MODEL public class ProductCommandHandler : IHandles<AddContentToProductCommand> { public Task Handle(AddContentToProductCommand command) { if(_productRepository.Exists(command.ProductId)) { if(command.ColorCode.Lenght > 50) { throw new BusinessException("ColorCode can not be greater than 50"); } Product aggregate = _productRepository.Get(command.ProductId); if(aggregate == null) { throw new AggregateNotFoundException(command.ProductId); } ProductContent productContent = _productContentRepository .GetByCodeAndProductId(command.ColorCode, command.ProductId); if(productContent != null) { throw new BusinessException($"Content already added {command.ColorCode}"); } aggregate.Contents.Add(new ProductContent(aggregate, command.ColorCode)); _productRepository.Save(aggregate); } } }
  • 13. ANEMIC DOMAIN MODEL public class ProductCommandHandler : IHandles<AddContentToProductCommand> { public Task Handle(AddContentToProductCommand command) { _productRepository .Get(command.ProductId) .Match( product => product.AddContent(command.ColorCode), () => throw new AggregateNotFoundException(command.ProductId); ); } } ▸
  • 14. ANEMIC DOMAIN MODEL public class Product : AggregateRoot { public ICollection<ProductContent> Contents; protected Product() { Register<Events.ContentAddedToProduct>(When); } public void AddContent(string colorCode) { if(colorCode.Lenght > 50) { throw new BusinessException("ColorCode can not be greater than 50"); } if(Contents.Any(x => x.ColorCode == colorCode)) { throw new BusinessException($"Content already added {colorCode}"); } ApplyChange( new Events.ContentAddedToProduct(this.Id, colorCode); ) } private void When(Events.ContentAddedToProduct @event) { Contents.Add(new ProductContent(this, @event.ColorCode)); } }
  • 15. BOUNDED CONTEXT PER MICRO SERVICE MICROSERVICES
  • 16. BOUNDED CONTEXT PER MICRO-SERVICE
  • 17. BOUNDED CONTEXT PER MICRO-SERVICE
  • 18. IMPEDANCE MISMATCH & CQRS WHAT ABOUT PERFORMANCE ?
  • 19. IMPEDANCE MISMATCH & CQRS Set(x => x.Products, c => { c.Fetch(CollectionFetchMode.Join); c.BatchSize(100); c.Lazy(CollectionLazy.Lazy); c.Access(Accessor.Field); c.Sort<CustomComparer>(); c.Type<CustomType>(); c.Persister<CustomPersister>(); c.OptimisticLock(true); c.Mutable(true); c.Cache(x => { x.Include(CacheInclude.All); x.Usage(CacheUsage.ReadOnly); x.Region("regionName"); }); c.SqlDelete("SQL command"); c.SqlDeleteAll("SQL command"); c.SqlInsert("SQL command"); c.SqlUpdate("SQL command"); c.Subselect("SQL command"); c.Loader("loaderRef"); }, r => { r.Element(e => { }); r.Component(c => { }); r.OneToMany(o => { }); r.ManyToMany(m => { }); r.ManyToAny<IAnyType>(m => { }); }); c.Table("tableName"); c.Schema("schemaName"); c.Catalog("catalogName"); c.Cascade(Cascade.All); c.Inverse(true); c.Where("SQL command"); c.Filter("filterName", f => f.Condition("condition")); c.OrderBy(x => x.Name); // or SQL expression c.Key(k => { k.Column("columnName"); k.Column(x => { x.Name("columnName"); }); k.ForeignKey("collection_fk"); k.NotNullable(true); k.OnDelete(OnDeleteAction.NoAction); k.PropertyRef(x => x.Name); k.Unique(true); k.Update(true); });
  • 20. IMPEDANCE MISMATCH & CQRS DTO PURE SQL User Inputs Transactional ORM Session
  • 22. DOMAIN EVENTS public class Product : AggregateRoot { public ICollection<ProductContent> Contents; protected Product() { Register<Events.ContentAddedToProduct>(When); } } public abstract class AggregateRoot { private ICollection<object> _events; private Dictionary<Type, Action<object>> _routes; void Register<TEvent>(Action<TEvent> route) { _routes.Add(typeof(TEvent), route); } void ApplyChange(object @event) { _routes[@event.GetType()].Invoke(@event); } public ICollection<object> GetChanges() { return _events; } }
  • 23. ENTITY FRAMEWORK & EVENT PUBLISHING Func<Task> PrepareCompleteAction(TDbContext dbContext) { if (dbContext.ChangeTracker.HasChanges()) { List<EntityEntry> changes = dbContext.ChangeTracker.Entries().ToList(); IEnumerable<AggregateRoot> trackedChanges = changes.Where(x => x.Entity is AggregateRoot) .Select(x => (AggregateRoot)x.Entity); return async () => { List<Event> events = trackedChanges.SelectMany(x => x.GetChanges()).OfType<Event>().ToList(); foreach (Event @event in events) { await _publisher.Publish(@event); } }; } return () => Task.CompletedTask; }
  • 24. NHIBERNATE & EVENT PUBLISHING public class NHibernateInterceptor : EmptyInterceptor { private readonly IMediator _mediator; public override void PostFlush(ICollection entities) { var changes = entities.OfType<object>().Where(e => e is AggregateRoot); foreach (var entity in changes) { TriggerDomainEvents(entity); } base.PostFlush(entities); } protected virtual void TriggerDomainEvents(object entity) { var aggregateChangeTracker = (AggregateRoot) entity; if (!aggregateChangeTracker.GetChanges().Any()) { return; } var domainEvents = aggregateChangeTracker.GetChanges().ToList(); aggregateChangeTracker.ClearChanges(); foreach (var @event in domainEvents) { _mediator.Publish((INotification) @event); } } }