{"id":318473,"date":"2021-02-23T21:00:27","date_gmt":"2021-02-23T21:00:27","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=318473"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=318473","title":{"rendered":"\u041f\u0430\u0442\u0442\u0435\u0440\u043d CQRS: \u0442\u0435\u043e\u0440\u0438\u044f \u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 ASP.Net Core 5"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9e1\/46a\/687\/9e146a6871ec71593a07251704e81891.png\" width=\"1560\" height=\"881\"><figcaption><\/figcaption><\/figure>\n<p>\u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439. \u0414\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u041f\u041e \u043d\u0435\u0442 \u0441\u0442\u0430\u043d\u0434<\/p>\n<p>\u0430\u0440\u0442\u043e\u0432 \u0438 \u0413\u041e\u0421\u0422\u043e\u0432, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. \u041e\u0434\u0438\u043d \u0438\u0437 \u043b\u0443\u0447\u0448\u0438\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u2014 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f CQRS.&nbsp;<\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0440\u0438 \u0432\u0438\u0434\u0430 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 CQRS: Regular, Progressive \u0438 Deluxe. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u043f\u0435\u0440\u0432\u043e\u043c \u2014 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0435 Regular CQRS, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432 DD Planet \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u043d\u043b\u0430\u0439\u043d-\u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u00ab\u0412\u044b\u0431\u0435\u0440\u0443.\u0440\u0443\u00bb. Progressive \u0438 Deluxe \u2014 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0438 \u0432\u043b\u0435\u043a\u0443\u0442 \u0437\u0430 \u0441\u043e\u0431\u043e\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u0448\u0438\u0440\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439.<\/p>\n<p>\u042f \u043f\u043e\u0434\u0435\u043b\u044e\u0441\u044c \u043e\u043f\u044b\u0442\u043e\u043c \u0441\u0432\u043e\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b: \u043a\u0430\u043a \u043c\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d CQRS \u0432 \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u0438 \u0431\u0435\u0441\u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u043e \u0432\u043d\u0435\u0434\u0440\u0438\u043b\u0438 \u0435\u0433\u043e \u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b, \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u044f \u0442\u044b\u0441\u044f\u0447\u0438 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430.&nbsp;<\/p>\n<h2>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 Onion<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u0435\u043d \u043f\u0430\u0442\u0442\u0435\u0440\u043d CQRS, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u00ab\u043b\u0443\u043a\u043e\u0432\u0430\u044f\u00bb \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u043b\u043e\u0435\u0432:<\/p>\n<ol>\n<li>\n<p><strong>\u0414\u043e\u043c\u0435\u043d\u043d\u044b\u0439 \u0441\u043b\u043e\u0439<\/strong> \u2014 \u043d\u0430\u0448\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438 \u043a\u043b\u0430\u0441\u0441\u044b.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043b\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438<\/strong>, \u0433\u0434\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043b\u043e\u0439 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/strong> \u2014 \u043b\u043e\u0433\u0438\u043a\u0430 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u043d\u0435\u0448\u043d\u0438\u0435 \u0441\u043b\u043e\u0438<\/strong>: \u0441\u043b\u043e\u0439 UI, \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/807\/49e\/1bc\/80749e1bcccf8f439e1a1a71797e42cd.png\" width=\"800\" height=\"800\"><figcaption><\/figcaption><\/figure>\n<p>\u042d\u0442\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043b\u0435\u0442, \u043d\u043e \u043e\u043d\u0430 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432.&nbsp;<\/p>\n<p>\u0422\u0430\u043a \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0441 \u043d\u0430\u0448\u0438\u043c \u0441\u0430\u0439\u0442\u043e\u043c \u00ab\u0412\u044b\u0431\u0435\u0440\u0443.\u0440\u0443\u00bb. \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u043f\u0430\u0433\u0435\u0442\u0442\u0438-\u043a\u043e\u0434, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u044c \u0431\u044b\u043b\u0430 \u043d\u0430 \u043e\u0447\u0435\u043d\u044c \u0432\u044b\u0441\u043e\u043a\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435. \u041d\u043e\u0432\u044b\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u0438 \u0432 \u0448\u043e\u043a, \u043a\u043e\u0433\u0434\u0430 \u0435\u0433\u043e \u0432\u0438\u0434\u0435\u043b\u0438. \u0421\u0430\u043c\u043e\u0435 \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0435, \u0447\u0442\u043e \u043c\u043e\u0433\u043b\u043e \u0441\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u2014 \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u041e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0438 \u043f\u043e\u0447\u0435\u043c\u0443, \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c.<\/p>\n<p>\u0418 \u043c\u044b \u043f\u043e\u0434\u043e\u0448\u043b\u0438 \u043a \u043c\u043e\u043c\u0435\u043d\u0442\u0443, \u043a\u043e\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u0432\u0441\u0442\u0430\u043b\u0430 \u0432\u0430\u0436\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u2014 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u043c\u0435\u043d\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u044c \u0438 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0441\u0432\u044f\u0437\u043d\u043e\u0441\u0442\u044c. \u041c\u044b \u043d\u0430\u0447\u0430\u043b\u0438 \u0438\u0441\u043a\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438\u0441\u044c \u043d\u0430 CQRS.&nbsp;<\/p>\n<h2>CQRS<\/h2>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9c0\/86a\/152\/9c086a152683b154c0c32cb454078225.png\" width=\"1600\" height=\"611\"><figcaption><\/figcaption><\/figure>\n<h3>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u0434\u0430\u0447\u0438&nbsp;<\/h3>\n<p><strong>CQRS (Command Query Responsibility Segregation)<\/strong>\u2014 \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0430 \u0434\u0432\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><strong>\u043a\u043e\u043c\u0430\u043d\u0434\u044b<\/strong>\u2014 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b;<\/p>\n<\/li>\n<li>\n<p><strong>\u0437\u0430\u043f\u0440\u043e\u0441\u044b<\/strong>\u2014 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0435.&nbsp;<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0438 \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0443\u0440\u043e\u0432\u043d\u044f\u0445. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043e\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0438 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0437\u0432\u0435\u043d\u044c\u044f (tiers), \u0438\u043b\u0438 \u0443\u0440\u043e\u0432\u043d\u0438.<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u044d\u0442\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0412 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f\u0445 \u044d\u0442\u043e\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0433\u043e \u0432 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u00ab\u0412\u044b\u0431\u0435\u0440\u0443.\u0440\u0443\u00bb, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447:<\/p>\n<ul>\n<li>\n<p>\u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0431\u0435\u0437 \u0443\u0449\u0435\u0440\u0431\u0430 \u0434\u043b\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e;&nbsp;<\/p>\n<\/li>\n<li>\n<p>\u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u0430 \u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0443;<\/p>\n<\/li>\n<li>\n<p>\u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0430\u0433\u043e\u0432;<\/p>\n<\/li>\n<li>\n<p>\u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432;<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f CQRS \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u0441\u0435 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u043e \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e (\u043c\u0435\u043d\u044c\u0448\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u044c, \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0432\u044f\u0437\u043d\u043e\u0441\u0442\u0438), \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u043a\u043e\u0434 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432\u0441\u0435 \u0435\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442, \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0434 \u043d\u0438\u043c \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b\/\u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0431\u0435\u0437 \u043a\u043e\u043f\u0430\u043d\u0438\u044f \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0447\u0430\u0441\u0442\u044f\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.&nbsp;<\/p>\n<h2>\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430<\/h2>\n<p>\u0425\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d CQRS \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435, \u0438 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043b\u044e\u0441\u044b.<\/p>\n<p>\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c ASP.NET Core 5.0, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0431\u0443\u0434\u0443\u0442 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u044d\u0442\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430.<\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 ASP.NET Core 5.0, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0435\u0449\u0435 \u0434\u0432\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/jbogard\/MediatR\" rel=\"noopener noreferrer nofollow\"><strong>MediatR<\/strong><\/a>\u2014 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0449\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0442\u0442\u0435\u0440\u043d Mediator, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u0431\u043c\u0435\u043d \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u043c \u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438\/\u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438 \u0431\u0435\u0437 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/fluentvalidation.net\" rel=\"noopener noreferrer nofollow\"><strong>FluentValidation<\/strong><\/a>\u2014 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u043b\u044f .NET, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Fluent-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438 \u043b\u044f\u043c\u0431\u0434\u0430-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u0440\u0430\u0432\u0438\u043b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f REST API \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e CQRS<\/h4>\n<p>\u041d\u0430\u0448\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u043b\u043e\u0436\u0430\u0442\u0441\u044f \u043d\u0430 REST API:<\/p>\n<ul>\n<li>\n<p><em>get<\/em> \u2014 \u044d\u0442\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u044b;&nbsp;<\/p>\n<\/li>\n<li>\n<p><em>post, put, delete<\/em> \u2014 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 MediatR: <\/h4>\n<p>\u0427\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0432 \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<blockquote>\n<p><em>dotnet add package MediatR.Extensions.Microsoft.DependencyInjection<\/em><\/p>\n<\/blockquote>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043d\u0430\u0448\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 ConfigureServices \u043a\u043b\u0430\u0441\u0441\u0430 Startup:<\/p>\n<pre><code class=\"cs\">namespace CQRS.Sample {    public class Startup    {        ...        public void ConfigureServices(IServiceCollection services)        {            ...            services.AddMediatR(Assembly.GetExecutingAssembly());            services.AddControllers();            ...        }    } } <\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043c\u044b \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0435\u0440\u0432\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u043f\u0443\u0441\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 \u0432 \u043d\u0430\u0448\u0443 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043e\u0442\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u043e\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0432 MediatR \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 IRequest&lt;TResponse&gt;, \u0432 \u043d\u0435\u043c \u043c\u044b \u043e\u043f\u0438\u0448\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u0447\u0442\u043e \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c.<\/p>\n<pre><code class=\"cs\">namespace CQRS.Sample.Features {    public class AddProductCommand : IRequest&lt;Product&gt;    {        \/\/\/ &lt;summary&gt;        \/\/\/     \u0410\u043b\u0438\u0430\u0441 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        public string Alias { get; set; }          \/\/\/ &lt;summary&gt;        \/\/\/     \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        public string Name { get; set; }          \/\/\/ &lt;summary&gt;        \/\/\/     \u0422\u0438\u043f \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        public ProductType Type { get; set; }    } }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e IRequestHandler&lt;TCommand, TResponse&gt;.&nbsp;<\/p>\n<p>\u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u043c\u044b \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u044b \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435, \u0438 \u043f\u0438\u0448\u0435\u043c \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0443, \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432 \u0411\u0414.<\/p>\n<pre><code class=\"cs\">namespace CQRS.Sample.Features {    public class AddProductCommand : IRequest&lt;Product&gt;    {        \/\/\/ &lt;summary&gt;        \/\/\/     \u0410\u043b\u0438\u0430\u0441 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        public string Alias { get; set; }          \/\/\/ &lt;summary&gt;        \/\/\/     \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        public string Name { get; set; }          \/\/\/ &lt;summary&gt;        \/\/\/     \u0422\u0438\u043f \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        public ProductType Type { get; set; }          public class AddProductCommandHandler : IRequestHandler&lt;AddProductCommand, Product&gt;        {            private readonly IProductsRepository _productsRepository;              public AddProductCommandHandler(IProductsRepository productsRepository)            {                _productsRepository = productsRepository ?? throw new ArgumentNullException(nameof(productsRepository));            }              public async Task&lt;Product&gt; Handle(AddProductCommand command, CancellationToken cancellationToken)            {                Product product = new Product();                product.Alias = command.Alias;                product.Name = command.Name;                product.Type = command.Type;                  await _productsRepository.Add(product);                return product;            }        }    } }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c Action \u0432 \u043d\u0443\u0436\u043d\u043e\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435, \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0438\u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 IMediator \u043a\u0430\u043a \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u044d\u043a\u0448\u0435\u043d\u0430 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043d\u0430\u0448\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u0447\u0442\u043e\u0431\u044b \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 ASP.Net Core \u0441\u043c\u043e\u0433 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u0442\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0447\u0435\u0440\u0435\u0437 MediatR \u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<pre><code class=\"cs\">namespace CQRS.Sample.Controllers {    [Route(\"api\/v{version:apiVersion}\/[controller]\")]    [ApiController]    public class ProductsController : ControllerBase    {        private readonly ILogger&lt;ProductsController&gt; _logger;        private readonly IMediator _mediator;          public ProductsController(IMediator mediator)        {            _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));        }                ...          \/\/\/ &lt;summary&gt;        \/\/\/     \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        \/\/\/ &lt;param name=\"client\"&gt;&lt;\/param&gt;        \/\/\/ &lt;param name=\"apiVersion\"&gt;&lt;\/param&gt;        \/\/\/ &lt;param name=\"token\"&gt;&lt;\/param&gt;        \/\/\/ &lt;returns&gt;&lt;\/returns&gt;        [HttpPost]        [ProducesResponseType(typeof(Product), StatusCodes.Status201Created)]        [ProducesDefaultResponseType]        public async Task&lt;IActionResult&gt; Post([FromBody] AddProductCommand client, ApiVersion apiVersion,            CancellationToken token)        {            Product entity = await _mediator.Send(client, token);            return CreatedAtAction(nameof(Get), new {id = entity.Id, version = apiVersion.ToString()}, entity);        }    } }<\/code><\/pre>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c MediatR \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0435 \u0440\u0430\u0437\u043d\u044b\u0435 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u043a\u043e\u043c\u0430\u043d\u0434\/\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430, \u043f\u043e \u0441\u0443\u0442\u0438, \u0442\u043e\u0442 \u0436\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 Middlewares \u0432 ASP.Net Core \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434 \u0438\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434.<\/p>\n<p>\u041d\u0430\u043c \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u0430\u043d\u0434 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e FluentValidation.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c FluentValidation \u0432 \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442:<\/p>\n<blockquote>\n<p><em>dotnet add package FluentValidation.AspNetCore<\/em><\/p>\n<\/blockquote>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c Pipeline \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cs\">namespace CQRS.Sample.Behaviours {    public class ValidationBehaviour&lt;TRequest, TResponse&gt; : IPipelineBehavior&lt;TRequest, TResponse&gt;        where TRequest : IRequest&lt;TResponse&gt;    {        private readonly ILogger&lt;ValidationBehaviour&lt;TRequest, TResponse&gt;&gt; _logger;        private readonly IEnumerable&lt;IValidator&lt;TRequest&gt;&gt; _validators;          public ValidationBehaviour(IEnumerable&lt;IValidator&lt;TRequest&gt;&gt; validators,            ILogger&lt;ValidationBehaviour&lt;TRequest, TResponse&gt;&gt; logger)        {            _validators = validators;            _logger = logger;        }          public async Task&lt;TResponse&gt; Handle(TRequest request, CancellationToken cancellationToken,            RequestHandlerDelegate&lt;TResponse&gt; next)        {            if (_validators.Any())            {                string typeName = request.GetGenericTypeName();                  _logger.LogInformation(\"----- Validating command {CommandType}\", typeName);                    ValidationContext&lt;TRequest&gt; context = new ValidationContext&lt;TRequest&gt;(request);                ValidationResult[] validationResults =                    await Task.WhenAll(_validators.Select(v =&gt; v.ValidateAsync(context, cancellationToken)));                List&lt;ValidationFailure&gt; failures = validationResults.SelectMany(result =&gt; result.Errors)                    .Where(error =&gt; error != null).ToList();                if (failures.Any())                {                    _logger.LogWarning(                        \"Validation errors - {CommandType} - Command: {@Command} - Errors: {@ValidationErrors}\",                        typeName, request, failures);                      throw new CQRSSampleDomainException(                        $\"Command Validation Errors for type {typeof(TRequest).Name}\",                        new ValidationException(\"Validation exception\", failures));                }            }              return await next();        }    } }<\/code><\/pre>\n<p>\u0418 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e DI, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u0441\u0435\u0445 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u043e\u0432 \u0434\u043b\u044f FluentValidation.<\/p>\n<pre><code class=\"cs\">namespace CQRS.Sample {    public class Startup    {        ...        public void ConfigureServices(IServiceCollection services)        {            ...            services.AddTransient(typeof(IPipelineBehavior&lt;,&gt;), typeof(ValidationBehaviour&lt;,&gt;));            services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());            ...        }    } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440.<\/p>\n<pre><code class=\"cs\">public class AddProductCommandValidator : AbstractValidator&lt;AddProductCommand&gt; {    public AddProductCommandValidator()    {        RuleFor(c =&gt; c.Name).NotEmpty();        RuleFor(c =&gt; c.Alias).NotEmpty();    } }<\/code><\/pre>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c C#, FluentValidation \u0438 MediatR \u043d\u0430\u043c \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b\/\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<pre><code class=\"cs\">namespace CQRS.Sample.Features {    public class AddProductCommand : IRequest&lt;Product&gt;    {        \/\/\/ &lt;summary&gt;        \/\/\/     \u0410\u043b\u0438\u0430\u0441 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        public string Alias { get; set; }          \/\/\/ &lt;summary&gt;        \/\/\/     \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        public string Name { get; set; }          \/\/\/ &lt;summary&gt;        \/\/\/     \u0422\u0438\u043f \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        public ProductType Type { get; set; }          public class AddProductCommandHandler : IRequestHandler&lt;AddProductCommand, Product&gt;        {            private readonly IProductsRepository _productsRepository;              public AddProductCommandHandler(IProductsRepository productsRepository)            {                _productsRepository = productsRepository ?? throw new ArgumentNullException(nameof(productsRepository));            }              public async Task&lt;Product&gt; Handle(AddProductCommand command, CancellationToken cancellationToken)            {                Product product = new Product();                product.Alias = command.Alias;                product.Name = command.Name;                product.Type = command.Type;                  await _productsRepository.Add(product);                return product;            }        }          public class AddProductCommandValidator : AbstractValidator&lt;AddProductCommand&gt;        {            public AddProductCommandValidator()            {                RuleFor(c =&gt; c.Name).NotEmpty();                RuleFor(c =&gt; c.Alias).NotEmpty();            }        }    } }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b\u043e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 API \u0438 \u0440\u0435\u0448\u0438\u043b\u043e \u0432\u0441\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<p>\u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u0432\u0441\u0435\u043c \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430\u043c. \u0422\u0430\u043a, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0431\u044b\u0441\u0442\u0440\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u0438 \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.&nbsp;<\/p>\n<p>\u0422\u0435\u043a\u0443\u0449\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/github.com\/sla1k\/CQRSSample\/tree\/master\" rel=\"noopener noreferrer nofollow\"><u>\u043d\u0430 GitHub<\/u><\/a>.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/543828\/\"> https:\/\/habr.com\/ru\/post\/543828\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439. \u0414\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u041f\u041e \u043d\u0435\u0442 \u0441\u0442\u0430\u043d\u0434<\/p>\n<p>\u0430\u0440\u0442\u043e\u0432 \u0438 \u0413\u041e\u0421\u0422\u043e\u0432, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. \u041e\u0434\u0438\u043d \u0438\u0437 \u043b\u0443\u0447\u0448\u0438\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u2014 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f CQRS.&nbsp;<\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0440\u0438 \u0432\u0438\u0434\u0430 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 CQRS: Regular, Progressive \u0438 Deluxe. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u043f\u0435\u0440\u0432\u043e\u043c \u2014 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0435 Regular CQRS, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432 DD Planet \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u043d\u043b\u0430\u0439\u043d-\u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u00ab\u0412\u044b\u0431\u0435\u0440\u0443.\u0440\u0443\u00bb. Progressive \u0438 Deluxe \u2014 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0438 \u0432\u043b\u0435\u043a\u0443\u0442 \u0437\u0430 \u0441\u043e\u0431\u043e\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u0448\u0438\u0440\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439.<\/p>\n<p>\u042f \u043f\u043e\u0434\u0435\u043b\u044e\u0441\u044c \u043e\u043f\u044b\u0442\u043e\u043c \u0441\u0432\u043e\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b: \u043a\u0430\u043a \u043c\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d CQRS \u0432 \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u0438 \u0431\u0435\u0441\u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u043e \u0432\u043d\u0435\u0434\u0440\u0438\u043b\u0438 \u0435\u0433\u043e \u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b, \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u044f \u0442\u044b\u0441\u044f\u0447\u0438 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430.&nbsp;<\/p>\n<h2>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 Onion<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u0435\u043d \u043f\u0430\u0442\u0442\u0435\u0440\u043d CQRS, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u00ab\u043b\u0443\u043a\u043e\u0432\u0430\u044f\u00bb \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u043b\u043e\u0435\u0432:<\/p>\n<ol>\n<li>\n<p><strong>\u0414\u043e\u043c\u0435\u043d\u043d\u044b\u0439 \u0441\u043b\u043e\u0439<\/strong> \u2014 \u043d\u0430\u0448\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438 \u043a\u043b\u0430\u0441\u0441\u044b.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043b\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438<\/strong>, \u0433\u0434\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043b\u043e\u0439 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/strong> \u2014 \u043b\u043e\u0433\u0438\u043a\u0430 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u043d\u0435\u0448\u043d\u0438\u0435 \u0441\u043b\u043e\u0438<\/strong>: \u0441\u043b\u043e\u0439 UI, \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u042d\u0442\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043b\u0435\u0442, \u043d\u043e \u043e\u043d\u0430 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432.&nbsp;<\/p>\n<p>\u0422\u0430\u043a \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0441 \u043d\u0430\u0448\u0438\u043c \u0441\u0430\u0439\u0442\u043e\u043c \u00ab\u0412\u044b\u0431\u0435\u0440\u0443.\u0440\u0443\u00bb. \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u043f\u0430\u0433\u0435\u0442\u0442\u0438-\u043a\u043e\u0434, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u044c \u0431\u044b\u043b\u0430 \u043d\u0430 \u043e\u0447\u0435\u043d\u044c \u0432\u044b\u0441\u043e\u043a\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435. \u041d\u043e\u0432\u044b\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u0438 \u0432 \u0448\u043e\u043a, \u043a\u043e\u0433\u0434\u0430 \u0435\u0433\u043e \u0432\u0438\u0434\u0435\u043b\u0438. \u0421\u0430\u043c\u043e\u0435 \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0435, \u0447\u0442\u043e \u043c\u043e\u0433\u043b\u043e \u0441\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u2014 \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u041e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0438 \u043f\u043e\u0447\u0435\u043c\u0443, \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c.<\/p>\n<p>\u0418 \u043c\u044b \u043f\u043e\u0434\u043e\u0448\u043b\u0438 \u043a \u043c\u043e\u043c\u0435\u043d\u0442\u0443, \u043a\u043e\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u0432\u0441\u0442\u0430\u043b\u0430 \u0432\u0430\u0436\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u2014 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u043c\u0435\u043d\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u044c \u0438 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0441\u0432\u044f\u0437\u043d\u043e\u0441\u0442\u044c. \u041c\u044b \u043d\u0430\u0447\u0430\u043b\u0438 \u0438\u0441\u043a\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438\u0441\u044c \u043d\u0430 CQRS.&nbsp;<\/p>\n<h2>CQRS<\/h2>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u0434\u0430\u0447\u0438&nbsp;<\/h3>\n<p><strong>CQRS (Command Query Responsibility Segregation)<\/strong>\u2014 \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0430 \u0434\u0432\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><strong>\u043a\u043e\u043c\u0430\u043d\u0434\u044b<\/strong>\u2014 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b;<\/p>\n<\/li>\n<li>\n<p><strong>\u0437\u0430\u043f\u0440\u043e\u0441\u044b<\/strong>\u2014 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0435.&nbsp;<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0438 \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0443\u0440\u043e\u0432\u043d\u044f\u0445. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043e\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0438 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0437\u0432\u0435\u043d\u044c\u044f (tiers), \u0438\u043b\u0438 \u0443\u0440\u043e\u0432\u043d\u0438.<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u044d\u0442\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0412 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f\u0445 \u044d\u0442\u043e\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0433\u043e \u0432 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u00ab\u0412\u044b\u0431\u0435\u0440\u0443.\u0440\u0443\u00bb, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447:<\/p>\n<ul>\n<li>\n<p>\u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0431\u0435\u0437 \u0443\u0449\u0435\u0440\u0431\u0430 \u0434\u043b\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e;&nbsp;<\/p>\n<\/li>\n<li>\n<p>\u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u0430 \u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0443;<\/p>\n<\/li>\n<li>\n<p>\u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0430\u0433\u043e\u0432;<\/p>\n<\/li>\n<li>\n<p>\u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432;<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f CQRS \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u0441\u0435 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u043e \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e (\u043c\u0435\u043d\u044c\u0448\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u044c, \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0432\u044f\u0437\u043d\u043e\u0441\u0442\u0438), \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u043a\u043e\u0434 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432\u0441\u0435 \u0435\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442, \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0434 \u043d\u0438\u043c \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b\/\u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0431\u0435\u0437 \u043a\u043e\u043f\u0430\u043d\u0438\u044f \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0447\u0430\u0441\u0442\u044f\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.&nbsp;<\/p>\n<h2>\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430<\/h2>\n<p>\u0425\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d CQRS \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435, \u0438 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043b\u044e\u0441\u044b.<\/p>\n<p>\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c ASP.NET Core 5.0, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0431\u0443\u0434\u0443\u0442 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u044d\u0442\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430.<\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 ASP.NET Core 5.0, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0435\u0449\u0435 \u0434\u0432\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/jbogard\/MediatR\" rel=\"noopener noreferrer nofollow\"><strong>MediatR<\/strong><\/a>\u2014 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0449\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0442\u0442\u0435\u0440\u043d Mediator, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u0431\u043c\u0435\u043d \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u043c \u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438\/\u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438 \u0431\u0435\u0437 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/fluentvalidation.net\" rel=\"noopener noreferrer nofollow\"><strong>FluentValidation<\/strong><\/a>\u2014 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u043b\u044f .NET, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Fluent-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438 \u043b\u044f\u043c\u0431\u0434\u0430-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u0440\u0430\u0432\u0438\u043b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f REST API \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e CQRS<\/h4>\n<p>\u041d\u0430\u0448\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u043b\u043e\u0436\u0430\u0442\u0441\u044f \u043d\u0430 REST API:<\/p>\n<ul>\n<li>\n<p><em>get<\/em> \u2014 \u044d\u0442\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u044b;&nbsp;<\/p>\n<\/li>\n<li>\n<p><em>post, put, delete<\/em> \u2014 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 MediatR: <\/h4>\n<p>\u0427\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0432 \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<blockquote>\n<p><em>dotnet add package MediatR.Extensions.Microsoft.DependencyInjection<\/em><\/p>\n<\/blockquote>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043d\u0430\u0448\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 ConfigureServices \u043a\u043b\u0430\u0441\u0441\u0430 Startup:<\/p>\n<pre><code class=\"cs\">namespace CQRS.Sample {    public class Startup    {        ...        public void ConfigureServices(IServiceCollection services)        {            ...            services.AddMediatR(Assembly.GetExecutingAssembly());            services.AddControllers();            ...        }    } } <\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043c\u044b \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0435\u0440\u0432\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u043f\u0443\u0441\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 \u0432 \u043d\u0430\u0448\u0443 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043e\u0442\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u043e\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0432 MediatR \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 IRequest&lt;TResponse&gt;, \u0432 \u043d\u0435\u043c \u043c\u044b \u043e\u043f\u0438\u0448\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u0447\u0442\u043e \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c.<\/p>\n<pre><code class=\"cs\">namespace CQRS.Sample.Features {    public class AddProductCommand : IRequest&lt;Product&gt;    {        \/\/\/ &lt;summary&gt;        \/\/\/     \u0410\u043b\u0438\u0430\u0441 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        public string Alias { get; set; }          \/\/\/ &lt;summary&gt;        \/\/\/     \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        public string Name { get; set; }          \/\/\/ &lt;summary&gt;        \/\/\/     \u0422\u0438\u043f \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        public ProductType Type { get; set; }    } }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e IRequestHandler&lt;TCommand, TResponse&gt;.&nbsp;<\/p>\n<p>\u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u043c\u044b \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u044b \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435, \u0438 \u043f\u0438\u0448\u0435\u043c \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0443, \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432 \u0411\u0414.<\/p>\n<pre><code class=\"cs\">namespace CQRS.Sample.Features {    public class AddProductCommand : IRequest&lt;Product&gt;    {        \/\/\/ &lt;summary&gt;        \/\/\/     \u0410\u043b\u0438\u0430\u0441 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        public string Alias { get; set; }          \/\/\/ &lt;summary&gt;        \/\/\/     \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        public string Name { get; set; }          \/\/\/ &lt;summary&gt;        \/\/\/     \u0422\u0438\u043f \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        public ProductType Type { get; set; }          public class AddProductCommandHandler : IRequestHandler&lt;AddProductCommand, Product&gt;        {            private readonly IProductsRepository _productsRepository;              public AddProductCommandHandler(IProductsRepository productsRepository)            {                _productsRepository = productsRepository ?? throw new ArgumentNullException(nameof(productsRepository));            }              public async Task&lt;Product&gt; Handle(AddProductCommand command, CancellationToken cancellationToken)            {                Product product = new Product();                product.Alias = command.Alias;                product.Name = command.Name;                product.Type = command.Type;                  await _productsRepository.Add(product);                return product;            }        }    } }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c Action \u0432 \u043d\u0443\u0436\u043d\u043e\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435, \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0438\u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 IMediator \u043a\u0430\u043a \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u044d\u043a\u0448\u0435\u043d\u0430 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043d\u0430\u0448\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u0447\u0442\u043e\u0431\u044b \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 ASP.Net Core \u0441\u043c\u043e\u0433 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u0442\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0447\u0435\u0440\u0435\u0437 MediatR \u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<pre><code class=\"cs\">namespace CQRS.Sample.Controllers {    [Route(\"api\/v{version:apiVersion}\/[controller]\")]    [ApiController]    public class ProductsController : ControllerBase    {        private readonly ILogger&lt;ProductsController&gt; _logger;        private readonly IMediator _mediator;          public ProductsController(IMediator mediator)        {            _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));        }                ...          \/\/\/ &lt;summary&gt;        \/\/\/     \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430        \/\/\/ &lt;\/summary&gt;        \/\/\/ &lt;param name=\"client\"&gt;&lt;\/param&gt;        \/\/\/ &lt;param name=\"apiVersion\"&gt;&lt;\/param&gt;        \/\/\/ &lt;param name=\"token\"&gt;&lt;\/param&gt;        \/\/\/ &lt;returns&gt;&lt;\/returns&gt;        [HttpPost]        [ProducesResponseType(typeof(Product), StatusCodes.Status201Created)]        [ProducesDefaultResponseType]        public async Task&lt;IActionResult&gt; Post([FromBody] AddProductCommand client, ApiVersion apiVersion,            CancellationToken token)        {            Product entity = await _mediator.Send(client, token);            return CreatedAtAction(nameof(Get), new {id = entity.Id, version = apiVersion.ToString()}, entity);        }    } }<\/code><\/pre>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c MediatR \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0435 \u0440\u0430\u0437\u043d\u044b\u0435 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u043a\u043e\u043c\u0430\u043d\u0434\/\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430, \u043f\u043e \u0441\u0443\u0442\u0438, \u0442\u043e\u0442 \u0436\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 Middlewares \u0432 ASP.Net Core \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434 \u0438\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434.<\/p>\n<p>\u041d\u0430\u043c \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u0430\u043d\u0434 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e FluentValidation.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c FluentValidation \u0432 \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442:<\/p>\n<blockquote>\n<p><em>dotnet add package FluentValidation.AspNetCore<\/em><\/p>\n<\/blockquote>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c Pipeline \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cs\">namespace CQRS.Sample.Behaviours {    public class ValidationBehaviour&lt;TRequest, TResponse&gt; : IPipelineBehavior&lt;TRequest, TResponse&gt;        where TRequest : IRequest&lt;TResponse&gt;    {        private readonly ILogger&lt;ValidationBehaviour&lt;TRequest, TResponse&gt;&gt; _logger;        private readonly IEnumerable&lt;IValidator&lt;TRequest&gt;&gt; _validators;          public ValidationBehaviour(IEnumerable&lt;IValidator&lt;TRequest&gt;&gt; validators,            ILogger&lt;ValidationBehaviour&lt;TRequest, TResponse&gt;&gt; logger)        {            _validators = validators;            _logger = logger;        }          public async Task&lt;TResponse&gt; Handle(TRequest request, CancellationToken cancellationToken,            RequestHandlerDelegate&lt;TResponse&gt; next)        {            if (_validators.Any())            {                string typeName = request.GetGenericTypeName();                  _logger.LogInformation(\"----- Validating command {CommandType}\", typeName);                    ValidationContext&lt;TRequest&gt; context = new ValidationContext&lt;TRequest&gt;(request);                ValidationResult[] validationResults =                    await Task.WhenAll(_validators.Select(v =&gt; v.ValidateAsync(context, cancellationToken)));                List&lt;ValidationFailure&gt; failures = validationResults.SelectMany(result =&gt; result.Errors)                    .Where(error =&gt; error !=<\/code><\/pre>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-318473","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/318473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=318473"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/318473\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=318473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=318473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=318473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}