O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.
Command Query Separation And what it brings to your day job        Dennis Doomen
About Me• Principal Consultant     • Speaker• 16 years IT experience   • Public initiatives• C++ origins but since       –...
WHAT IS CQS AND WHY SHOULDYOU USE IT?
“…asking a questionshould not change the      answer…”PROF. BERTRAND MEYER
CQS IN PRACTICEmyObject .UseRepository("Stuff") .WithTransactionSupport()  .Retries(3) .LogWarnings() .LogErrors();var new...
AND ANOTHER EXAMPLEvoid Push(T t);T Pop();bool IsEmpty { get; }public interface IStack<T> :IEnumerable<T>  {     IStack<T>...
SO WHAT’S CQRS THEN?
“CQRS is a simple pattern that strictly segregates the responsibility of handling    command input into an autonomoussyste...
CQRS = CQS on Architecture Level                                           Front-End                                      ...
Scaling Opportunities                                      Front-End                         Querying                 Quer...
Myths of CQRS• It is an architecture (style)• It should be used by default• It requires Event Sourcing• It requires eventu...
HOW TO BUILD IT?
Approach1. Decide if you need it2. Reconsider if you need it3. Design your domain using   aggregates4. Add commands5. Add ...
Effective Aggregate Design
Effective Aggregate Design Model true                Designinvariants in              Smallconsistency              Aggreg...
How it works                       Execute query             Front-End             Send command                           ...
WebAPI,                                                  What to use? WCF, POCO                                           ...
Questions?Emaildennis.doomen@avivasolutions.nlTwitterddoomenSiteswww.dennisdoomen.netwww.csharpcodingguidelines.comfluenta...
Reading Material• Effective Aggregate Design  http://dddcommunity.org/library/vernon_2011• Meanwhile…on the command side o...
Próximos SlideShares
Carregando em…5
×

Command Query Separation And How It Helps In Your Daily Job

18.568 visualizações

Publicada em

The CQRS architecture has been very hot in the past two years. But by now, I think that the majority of the profession agrees that going all the way is only worthwhile for systems with some very specific requirements. Yet, I believe that the separation of reads and writes in an enterprise system has some interesting advantages. In the past year I have applied this principle to an ASP.NET WebForms project that had nothing to do with web services at all, but gave me a lot of benefits. Even my own initiative, the Silverlight Cookbook, is now based on that. I'd like to get a chance to explain you why I use this technique, why it has become part of my default reference architecture (regardless of the technology), and I'll share some of the advantages and disadvantages of that choice.

Publicada em: Tecnologia
  • Finally found a service provider which actually supplies an essay with an engaging introduction leading to the main body of the exposition Here is the site ⇒⇒⇒WRITE-MY-PAPER.net ⇐⇐⇐
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • My personal experience with research paper writing services was highly positive. I sent a request to ⇒ www.HelpWriting.net ⇐ and found a writer within a few minutes. Because I had to move house and I literally didn’t have any time to sit on a computer for many hours every evening. Thankfully, the writer I chose followed my instructions to the letter. I know we can all write essays ourselves. For those in the same situation I was in, I recommend ⇒ www.HelpWriting.net ⇐.
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • Dating for everyone is here: ❶❶❶ http://bit.ly/2F90ZZC ❶❶❶
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • Sex in your area is here: ❤❤❤ http://bit.ly/2F90ZZC ❤❤❤
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui

Command Query Separation And How It Helps In Your Daily Job

  1. 1. Command Query Separation And what it brings to your day job Dennis Doomen
  2. 2. About Me• Principal Consultant • Speaker• 16 years IT experience • Public initiatives• C++ origins but since – Silverlight Cookbook 2001 addicated to C# – C# Coding Guidelines• Specialties – Fluent Assertions – Architecture • Internet – Scrum/XP – www.dennisdoomen.net – ALM – DZone MVB – @ddoomen
  3. 3. WHAT IS CQS AND WHY SHOULDYOU USE IT?
  4. 4. “…asking a questionshould not change the answer…”PROF. BERTRAND MEYER
  5. 5. CQS IN PRACTICEmyObject .UseRepository("Stuff") .WithTransactionSupport() .Retries(3) .LogWarnings() .LogErrors();var newObject = myObject .UseRepository("Stuff") .WithTransactionSupport() .Retries(3) .LogWarnings() .LogErrors();
  6. 6. AND ANOTHER EXAMPLEvoid Push(T t);T Pop();bool IsEmpty { get; }public interface IStack<T> :IEnumerable<T> { IStack<T> Push(T value); IStack<T> Pop(); T Peek(); bool IsEmpty { get; } }
  7. 7. SO WHAT’S CQRS THEN?
  8. 8. “CQRS is a simple pattern that strictly segregates the responsibility of handling command input into an autonomoussystem from the responsibility of handling side-effect-free query/read access on the same system.” CLEMENS VASTERS
  9. 9. CQRS = CQS on Architecture Level Front-End Sustains the user No O/R intentconversions Queries Business Actions Projections Commands Query Service Command Service Command Handlers Data Access Layer Domain Model Optimized Repositoriesfor querying Optimized for consistency Changes Relational Query Store Database Query Store Synchronous or asynchronous
  10. 10. Scaling Opportunities Front-End Querying Querying Command Side Querying Querying Query Store Query Store Relational Query Store DatabaseQuery Store
  11. 11. Myths of CQRS• It is an architecture (style)• It should be used by default• It requires Event Sourcing• It requires eventual consistency• It requires a bus/queues/asynchrony• Commands are fire-and-forget• Solves all concurrency problems• It is easy
  12. 12. HOW TO BUILD IT?
  13. 13. Approach1. Decide if you need it2. Reconsider if you need it3. Design your domain using aggregates4. Add commands5. Add queries
  14. 14. Effective Aggregate Design
  15. 15. Effective Aggregate Design Model true Designinvariants in Smallconsistency Aggregates boundaries Reference Update single other aggregate per aggregates by transaction identity
  16. 16. How it works Execute query Front-End Send command App QueryProcessor Command Service Find query handler Find command handler Registry Creates Creates Query Command Find by ID and/or versionHandler Handler Invoke method Unit-of- LINQ, HQL, SQL Work Domain Send domain event Aggregate Event Loads Simple Data Root Handler Access Layer Store denormalized data Store normalized data Read DB Write DB
  17. 17. WebAPI, What to use? WCF, POCO Front-End WCF, App POCO Autofac, Query Unity, Processor StructureMap Command Service Registry Query Command Handler Handler NHibernate Unit-of- EF, Dapper Work Domain Aggregate Event Simple Data Root Handler Access Layer Udi Dahan’s Domain Event Read DB Write DB SQL, Oracle, SQL, Oracle, RavenDB, RavenDB, NoSQL NoSQL
  18. 18. Questions?Emaildennis.doomen@avivasolutions.nlTwitterddoomenSiteswww.dennisdoomen.netwww.csharpcodingguidelines.comfluentassertions.codeplex.comsilverlightcookbook.codeplex.com
  19. 19. Reading Material• Effective Aggregate Design http://dddcommunity.org/library/vernon_2011• Meanwhile…on the command side of my architecture http://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=91• Meanwhile…on the query side of my architecture http://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=92• Busting some CQRS myths http://lostechies.com/jimmybogard/2012/08/22/busting-some-cqrs- myths/• Free MSDN eBook: Exploring CQRS and Event Sourcing http://www.microsoft.com/en-us/download/details.aspx?id=34774

×