{"id":300513,"date":"2020-03-21T21:00:16","date_gmt":"2020-03-21T21:00:16","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=300513"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2020-03-21T21:00:16","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=300513","title":{"rendered":"\u041e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u0434\u0430 \u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445 \u0438 \u043c\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0433\u0435\u043a\u0441\u0430\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0438 DDD"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/493426\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ak\/h6\/c_\/akh6c_safonprea6vtagzdaoy58.png\"><br \/>  \u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u0412 \u041c\u043e\u043d\u043e\u043b\u0438\u0442\u0435 \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432 \u0435\u0434\u0438\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435, a \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b, \u044f\u0437\u044b\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0441 1 \u2014 2 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u043c\u0438 \u0438 1 \u2014 10 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u043c\u0438 \u043e\u0441\u043e\u0431\u043e \u0441\u043c\u044b\u0441\u043b\u0430 \u0433\u043e\u0440\u043e\u0434\u0438\u0442\u044c \u0441\u043b\u043e\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439 \u043d\u0435\u0442. \u0414\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438 \u0438 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u043b\u0443\u0447\u0448\u0435 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043d\u0435 \u043b\u0435\u043d\u0438\u0442\u044c\u0441\u044f. \u042f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u043c\u043e\u0435\u043c \u043e\u043f\u044b\u0442\u0435 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 DDD, \u041f\u043e\u0440\u0442\u043e\u0432 \u0438 \u0410\u0434\u0430\u043f\u0442\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u043e\u0431\u043e\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432. \u0415\u0441\u0442\u044c \u043a\u0440\u0430\u0442\u043a\u043e \u0441\u0443\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438: \u0414\u0436\u0443\u043d \u2014 \u043f\u0438\u0448\u0435\u0442 \u043a\u043e\u0434 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435. \u041c\u0438\u0434\u043b \u2014 \u043f\u0438\u0448\u0435\u0442 \u043a\u0443\u0447\u0443 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439. \u0421\u0435\u043d\u044c\u043e\u0440 \u2014 \u0437\u043d\u0430\u0435\u0442 \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435, \u0430 \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u044b \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438.<a name=\"habracut\"><\/a> \u0422\u0443\u0442 \u043d\u0443\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u043e\u0447\u043a\u0443 \u043d\u0430\u0434 \u0418 \u2014 \u041f\u043e\u0440\u0442\u044b \u0432 \u0421# \u044d\u0442\u043e interface \u0438\u043b\u0438 abstract, \u0430 \u0410\u0434\u0430\u043f\u0442\u0435\u0440\u044b \u044d\u0442\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (class, struct). \u0412 \u0446\u0435\u043b\u044f\u0445 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 <a href=\"https:\/\/habr.com\/ru\/post\/427739\/\">DDD, Hexagonal, Onion, Clean, CQRS\u2026 \u043a\u0430\u043a \u044f \u0441\u043e\u0431\u0440\u0430\u043b \u0432\u0441\u0451 \u044d\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u0435<\/a> \u0438 \u0432\u043e\u0442 \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e <a href=\"https:\/\/habr.com\/ru\/company\/mobileup\/blog\/335382\/\">\u0417\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u044f Clean Architecture<\/a>. \u0422\u0443\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043c\u0435\u0439\u0442\u0435 \u0432 \u0432\u0438\u0434\u0443 \u0447\u0442\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0445\u043e\u0434 \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0430. \u042f \u0436\u0435 \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u044f\u0445 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445 80 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u0432 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0438 20 \u0441\u0440\u0435\u0434\u043d\u0435\u0439 \u0438\u043b\u0438 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438. <\/p>\n<h2>\u0422\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u044f<\/h2>\n<p>  <\/p>\n<h3>1)PrimaryAdapters<\/h3>\n<p>  \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0434\u043b\u044f \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0432\u043d\u0435\u0448\u043d\u0435\u0439 <b>\u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0439<\/b> \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439. \u0412\u044b\u0437\u044b\u0432\u0430\u044e\u0442 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 SecondaryApdapters \u0438 Logic. \u041e\u043d\u0438 \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u0447\u0442\u043e-\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0422\u043e\u0447\u043a\u0438 \u0432\u0445\u043e\u0434\u0430 \u0432 \u0432\u0430\u0448 \u043a\u043e\u0434. \u0422\u0438\u043f\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u0435\u043b\u0438: ItemsService, CreateItemCommandHandler. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 Logic \u0438 SecondaryAdapters \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<h3>2)SecondaryAdapters<\/h3>\n<p>  \u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a \u0432\u043d\u0435\u0448\u043d\u0435\u0439 <b>\u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439<\/b> \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439. \u041e\u043d \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043e\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0422\u0438\u043f\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u0435\u043b\u0438: ItemsRepository, EmailSender, Logger, DesturbedCache. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u0432\u0440\u043e\u0434\u0435 EntityFramework \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b. <\/p>\n<h3>3)Logic<\/h3>\n<p>  <\/p>\n<h4>3.1)Entities<\/h4>\n<p>  \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043b\u043e\u0433\u0438\u043a\u0443. \u0422\u0438\u043f\u0438\u0447\u043d\u044b\u0435 \u041e\u041e\u041f \u043e\u0431\u044a\u0435\u043a\u0442\u044b. Item, Money, User. \u0422\u0443\u0442 \u0442\u0430\u043a \u0436\u0435 \u043b\u0435\u0436\u0430\u0442 ValueObjects \u0438 Events. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438\u0437 \u0441\u043b\u043e\u044f Entities. \u041f\u043e \u0438\u0434\u0435\u0435 \u044d\u0442\u043e\u0442 \u0441\u043b\u043e\u0439 \u044d\u0442\u043e \u044f\u0434\u0440\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0438 \u043e\u0442 \u043a\u043e\u0433\u043e \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442. \u0412\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u043d\u0435\u0433\u043e.<\/p>\n<h4>3.2)DomainServices<\/h4>\n<p>  \u0413\u043e\u043b\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u041d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u043a\u0438 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u043a \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 Entities \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 DomainServices. <b>\u041d\u0438\u043a\u043e\u0433\u0434\u0430<\/b> \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 PrimaryAdapters (\u044d\u0442\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u0430\u043c\u0438 \u0432\u0441\u0435\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442) \u0438 SecondaryAdapters. \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u0432\u0441\u044f\u043a\u0438\u0435 AmountCalculator, Validator \u0438 \u043f\u0440\u043e\u0447\u0435\u0435. <br \/>  \u041f\u043e\u0442\u043e\u043a \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u043e\u0434\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432 \u043e\u0434\u043d\u043e\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 PrimaryAdapters -&gt; Logic \u0438 SecondaryAdapters.<\/p>\n<h3>Domain<\/h3>\n<p>  \u042d\u0442\u043e \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u041c\u0430\u0433\u0430\u0437\u0438\u043d\u0430 Domain \u044d\u0442\u043e E-Commerce.<\/p>\n<h3>BoundedContex<\/h3>\n<p>  BoundedContext \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0430 \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e. \u041e\u0434\u0438\u043d \u0438\u0437 \u043f\u0443\u0442\u0435\u0439 \u043a \u0443\u0441\u043f\u0435\u0445\u0443 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u044d\u0442\u043e \u043d\u0430\u0439\u0442\u0438 \u0438 \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0432 \u043d\u0435\u0439 \u0432\u0441\u0435 \u0435\u0435 BoundedContexts. \u0412 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 1 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441 = 1 BoundedContext. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: \u0423 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c BoundedContext \u041a\u043e\u0440\u0437\u0438\u043d\u044b \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0438 BoundedContext \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0437\u0430\u043a\u0430\u0437\u0430\u043c\u0438, BoundedContext \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438. \u041f\u0440\u0438\u0447\u0435\u043c \u043e\u0434\u0438\u043d \u0431\u043e\u043b\u044c\u0448\u043e\u0439 BoundedContext \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u0431\u0438\u0442 \u043d\u0430 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0435 \u043a\u0443\u0441\u043a\u0438 \u0432\u043d\u0443\u0442\u0440\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f BoundedContext \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0443 \u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0438\u0437 \u043a\u043e\u0440\u0437\u0438\u043d\u044b. \u0412 \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0435 1 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 BoundedContext \u044d\u0442\u043e \u043e\u0434\u0438\u043d \u041c\u043e\u0434\u0443\u043b\u044c. \u0422\u0443\u0442 \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435 \u0447\u0442\u043e \u0432\u0441\u0435 Entities \u0436\u0438\u0432\u0443\u0442 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0442.\u0435. Item \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0438 Item \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432\u0438\u0442\u0440\u0438\u043d\u044b \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u044d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438 \u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438. \u0412 \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0435 \u0438\u0445 \u043f\u0440\u043e\u0441\u0442\u043e \u043c\u0430\u043f\u043f\u044f\u0442 \u0434\u0440\u0443\u0433 \u0432 \u0434\u0440\u0443\u0433\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0411\u0414 \u043a\u0430\u043a\u0443\u044e \u043d\u0438\u0431\u0443\u0434\u044c ItemDto \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442 EF \u0438 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u043b\u044f \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u043d\u044b\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0442. \u0435. \u0435\u0441\u043b\u0438 \u0443 Item \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 (\u043c\u043e\u0434\u0443\u043b\u044f) \u041a\u043e\u0440\u0437\u0438\u043d\u044b \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e Property1, \u0430 \u0443 Item \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432\u0438\u0442\u0440\u0438\u043d\u044b \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e Property2 \u0442\u043e \u0443 ItemDto \u0431\u0443\u0434\u0435\u0442 \u0438 Property1 \u0438 Property2. \u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u0432\u043e\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0442\u044c \u0438\u0437 \u0431\u0430\u0437\u044b \u0443\u0436\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u043d\u0443\u044e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 Item. \u0412 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445 \u0441 \u044d\u0442\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e. \u0423 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0432\u043e\u044f \u0411\u0414 \u0438 \u0441\u0432\u043e\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. \u0423 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0438\u0440\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0441\u0432\u043e\u0438 \u043a\u043b\u0430\u0441\u0441\u044b. \u041f\u0440\u043e\u0441\u0442\u043e <b>\u043f\u043e\u043c\u043d\u0438\u0442\u0435<\/b> \u0447\u0442\u043e Item \u0438 ItemsRepository \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 BoundedContext \u044d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438. \u0427\u0430\u0441\u0442\u043e BoundedContext \u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445 \u043d\u0430\u0440\u0443\u0448\u0430\u044e\u0442 \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043e\u0431\u0449\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438\u043b\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 1 \u2014 2 \u043d\u0443\u0436\u043d\u044b\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u043c\u0443 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441 \u043e\u0431\u0449\u0438\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445 \u043d\u0430\u0434\u043e \u0431\u044b\u0442\u044c \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u044b\u043c\u0438.<\/p>\n<h2>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u043a\u043e\u0438\u0445 \u043f\u043e \u0437\u0430\u043a\u043e\u043d\u0443 \u041f\u0430\u0440\u0435\u0442\u043e 80 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u0432<\/h2>\n<p>  \u0412\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0441\u043b\u043e\u0439 PrimaryAdatapters \u0438 SecondaryAdapters. \u041e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0439 Logic. \u0422\u043e\u0447\u043d\u0435\u0435 \u0432 \u0442\u0438\u043f\u0438\u0447\u043d\u043e\u043c ASP.NET \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u2014 PimaryAdater \u044d\u0442\u043e Controller, \u0430 SecondaryAdapter \u044d\u0442\u043e DbContext \u043e\u0442 EF. \u0415\u0441\u043b\u0438 \u0432\u0434\u0440\u0443\u0433 Controller \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u0438\u043c, \u0442\u043e \u0440\u0435\u0436\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u0447\u0430\u0441\u0442\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e partial. \u042d\u0442\u043e \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043b\u0443\u0447\u0448\u0435 \u0447\u0435\u043c \u0440\u0430\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0435 \u043d\u0443\u0436\u043d\u044b\u0435 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u0438 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u043d\u0430 \u043d\u0438\u0445 \u0432\u0440\u0435\u043c\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a Microsoft \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u0432\u043e\u0435\u0433\u043e EShop \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u0434\u043e\u043a\u0435\u0440 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430\u0445 \u0442\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u043b\u0430 \u0434\u043b\u044f BasketMicrotservice. \u0414\u0430, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440. \u0422\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u043d\u0430\u0434\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043f\u0430\u0433\u0435\u0442\u0442\u0438-\u043a\u043e\u0434. <b>\u0412\u0430\u0436\u043d\u043e<\/b> \u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0447\u0442\u043e \u0441\u043b\u043e\u0439 Logic \u0443 \u043d\u0430\u0441 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0438 \u043c\u044b \u0432\u0441\u0435 \u0435\u0449\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Entities \u0441 \u0438\u0445 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0438 DomainServices \u0441 \u0438\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u0430 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0438\u0448\u0435\u043c \u0441\u0442\u0435\u043d\u0443 \u0441\u043f\u0430\u0433\u0435\u0442\u0442\u0438-\u043a\u043e\u0434 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435. \u041f\u0440\u043e\u0441\u0442\u043e \u043c\u044b \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0435 ItemService \u0438 ItemRepository. \u0421\u0442\u0430\u0440\u044b\u0435, \u0434\u043e\u0431\u0440\u044b\u0435 ItemValidator, ItemMapper, AmountCalculator \u0438 \u043f\u0440\u043e\u0447\u0435\u0435 \u0432 \u044d\u0442\u043e\u043c \u0434\u0443\u0445\u0435 \u0443 \u043d\u0430\u0441 \u0432\u0441\u0435 \u0435\u0449\u0435 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f. \u0422\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043b\u043e\u0439 Logic \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u043c\u0443 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0443 \u043d\u0430\u043a\u0440\u0443\u0442\u0438\u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439 ItemsService, ItemsRepository.<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440<\/h3>\n<p>  \u0421\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0446\u0435\u043d\u0443 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 \u0441\u043e \u0441\u043a\u0438\u0434\u043a\u043e\u0439. \u041f\u043e \u0438\u0434\u0435\u0435 \u043e\u043d \u0447\u0430\u0441\u0442\u044c Domain \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u041c\u0430\u0433\u0430\u0437\u0438\u043d\u0430 \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0435\u0433\u043e BoundedContext \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0442\u043e\u0432\u0430\u0440\u043e\u0432. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u044f \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u043b. \u0415\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043a\u0430\u043a\u043e\u043c \u043d\u0438\u0431\u0443\u0434\u044c ItemValidator \u0438 DiscountValidator.<\/p>\n<p>  1) \u041f\u0430\u043f\u043a\u0430 Logic:<br \/>  1.1) \u041f\u0430\u043f\u043a\u0430 Entities:<\/p>\n<p>  \u0421\u043a\u0438\u0434\u043a\u0430:  <\/p>\n<pre><code class=\"cs\">    public class Discount     {         [Key]         public Guid Id { get; set; }          public decimal Value { get; set; }     } <\/code><\/pre>\n<p>  \u0414\u0435\u043d\u044c\u0433\u0438:  <\/p>\n<pre><code class=\"cs\">    [Owned]     public class Money     {         public decimal Amount { get; set; }          public Money Apply(Discount discount)         {             var amount = Amount * (1 - discount.Value);             return new Money()             {                 Amount = amount             };         }     } <\/code><\/pre>\n<p>  \u0422\u043e\u0432\u0430\u0440:  <\/p>\n<pre><code class=\"cs\">    public class Item     {         [Key]         public Guid Id { get; set; }          public Money Price { get; set; } = new Money();     } <\/code><\/pre>\n<p>  1.2) \u041f\u0430\u043f\u043a\u0430 DomainServices<\/p>\n<p>  \u041a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440 \u0446\u0435\u043d\u044b \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0441\u043a\u0438\u0434\u043a\u0438:  <\/p>\n<pre><code class=\"cs\">    public interface IPriceCalculator     {         Money WithDiscounts(Item item, IEnumerable&lt;Discount&gt; discounts);     }       public sealed class PriceCalculator:IPriceCalculator     {         public Money WithDiscounts(Item item, IEnumerable&lt;Discount&gt; discounts)         {             return discounts.Aggregate(item.Price, (m, d) =&gt; m.Apply(d));         }     } <\/code><\/pre>\n<p>  2) DbContext   <\/p>\n<pre><code class=\"cs\">    public class ItemsContext : DbContext     {         public ItemsContext(DbContextOptions&lt;ItemsContext&gt; options) : base(options)         {          }          public DbSet&lt;Item&gt; Items { get; set; }          public DbSet&lt;Discount&gt; Discounts { get; set; }     } <\/code><\/pre>\n<p>  3) Controller  <\/p>\n<pre><code class=\"cs\">    [ApiController]     [Route(&quot;api\/v1\/items&quot;)]     public class ItemsController : ControllerBase     {         private readonly ItemsDbContext _context;         private readonly IPriceCalculator _priceCalculator;          public ItemsController(ItemsDbContext context, IPriceCalculator priceCalculator)         {             _context = context;             _priceCalculator = priceCalculator;         }          [HttpGet(&quot;{id}\/price-with-discounts&quot;)]         public async Task&lt;decimal&gt; GetPriceWithDiscount(Guid id)         {             var item = await _context.Items.FindAsync(id);             var discounts = await _context.Discounts.ToListAsync();             return _priceCalculator.WithDiscounts(item, discounts).Amount;         }     } <\/code><\/pre>\n<h2>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u043a\u043e\u0438\u0445 20 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u0432 \u0438 \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u043e\u0432<\/h2>\n<p>  \u0422\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u0437\u043e\u043b\u044f\u0446\u0438\u0435\u0439 \u0441\u043b\u043e\u0435\u0432 \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f PrimaryAdapter (ItemService) \u0438 \u0434\u043b\u044f SecondaryAdapter (ItemRepository). \u0412 \u043f\u0430\u043f\u043a\u0435 Logic \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u0434\u043e \u044d\u0442\u043e\u0433\u043e. <\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440<\/h3>\n<p>  1) \u041f\u0430\u043f\u043a\u0430 SecondaryAdapters  <\/p>\n<pre><code class=\"cs\">    public interface IItemsRepository     {         Task&lt;Item&gt; Get(Guid id);     }      public sealed class ItemsRepository : IItemsRepository     {         private readonly ItemsDbContext _context;          public ItemsRepository(ItemsDbContext context)         {             _context = context;         }          public async Task&lt;Item&gt; Get(Guid id)         {             var item = await _context.Items.FindAsync(id);             return item;         }     } <\/code><\/pre>\n<pre><code class=\"cs\">    public interface IDiscountsRepository     {         Task&lt;List&lt;Discount&gt;&gt; Get();     }      public sealed class DiscountsRepository : IDiscountsRepository     {         private readonly ItemsDbContext _context;          public DiscountsRepository(ItemsDbContext context)         {             _context = context;         }          public Task&lt;List&lt;Discount&gt;&gt; Get()         {             return _context.Discounts.ToListAsync();         }     } <\/code><\/pre>\n<p>  2) \u041f\u0430\u043f\u043a\u0430 PrimaryAdapters  <\/p>\n<pre><code class=\"cs\">    public interface IItemService     {         Task&lt;decimal&gt; GetPriceWithDiscount(Guid id);     }      public class ItemService : IItemService     {         private readonly IItemsRepository _items;         private readonly IDiscountsRepository _discounts;         private readonly IPriceCalculator _priceCalculator;          public ItemService(IItemsRepository items, IDiscountsRepository discounts, IPriceCalculator priceCalculator)         {             _items = items;             _discounts = discounts;             _priceCalculator = priceCalculator;         }          public async Task&lt;decimal&gt; GetPriceWithDiscount(Guid id)         {             var item = await _items.Get(id);             var discounts = await _discounts.Get();             return _priceCalculator.WithDiscounts(item, discounts).Amount;         }     } <\/code><\/pre>\n<p>  \u041d\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043d\u0430\u0448 IItemService  <\/p>\n<pre><code class=\"cs\">    [ApiController]     [Route(&quot;api\/v1\/items&quot;)]     public class ItemsController : ControllerBase     {         private readonly IItemService _service;          public ItemsController(IItemService service)         {             _service = service;         }          [HttpGet(&quot;{id}\/price-with-discounts&quot;)]         public async Task&lt;decimal&gt; GetPriceWithDiscount(Guid id)         {             var result = await _service.GetPriceWithDiscount(id);             return result;         }     } <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043b\u043e\u0441\u044c \u043c\u043d\u043e\u0433\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u0412\u0437\u0430\u043c\u0435\u043d \u043f\u043e\u0432\u044b\u0441\u0438\u043b\u0430\u0441\u044c \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0449\u0435 \u0441\u043c\u0435\u043d\u0438\u0442\u044c Contoller \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 ASP.NET Core \u043d\u0430 \u0447\u0442\u043e-\u0442\u043e \u0434\u0440\u0443\u0433\u043e\u0435 \u0438\u043b\u0438 \u0441\u043c\u0435\u043d\u0438\u0442\u044c DbContext \u0438 EntityFramework Core \u043d\u0430 \u0447\u0442\u043e-\u0442\u043e \u0434\u0440\u0443\u0433\u043e\u0435 \u0438\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 Redis. \u041f\u0435\u0440\u0432\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0432\u044b\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442 \u0432 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445 \u0438 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0438 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0445 \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0430\u0445. \u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u043e \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0438 \u0434\u043e\u043f\u0438\u043b\u0438\u0432\u0430\u0442\u044c \u0432\u0430\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043d\u0430\u0434\u043e \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0433\u043e\u0434\u0430. \u041d\u0443 \u0438 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043a\u0440\u043e\u043c\u0435 Entity Item \u0438 Discount \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 DTO \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c DbContex EF \u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 DTO (Models) \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c ASP.NET Controller \u0442.\u0435. ItemDto \u0438 ItemModel. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c\u0438. \u041d\u0443 \u0438 \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c 2 \u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 <a href=\"https:\/\/gitlab.com\/VictorWinbringer\/testruvds\" rel=\"nofollow\">TestRuvds<\/a>. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043e\u043d \u0442\u0443\u0442 \u0438\u0437\u043b\u0438\u0448\u0435\u043d \u0438 \u0432\u0441\u0435 \u044d\u0442\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u0442\u0443\u0442 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430.<\/p>\n<h2>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0441\u0442\u0438<\/h2>\n<p>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e <a href=\"https:\/\/habr.com\/ru\/users\/canxes\/\" class=\"user_link\">canxes<\/a> \u0437\u0430 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438.<\/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\/493426\/\"> https:\/\/habr.com\/ru\/post\/493426\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/493426\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ak\/h6\/c_\/akh6c_safonprea6vtagzdaoy58.png\"><br \/>  \u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u0412 \u041c\u043e\u043d\u043e\u043b\u0438\u0442\u0435 \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432 \u0435\u0434\u0438\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435, a \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b, \u044f\u0437\u044b\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0441 1 \u2014 2 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u043c\u0438 \u0438 1 \u2014 10 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u043c\u0438 \u043e\u0441\u043e\u0431\u043e \u0441\u043c\u044b\u0441\u043b\u0430 \u0433\u043e\u0440\u043e\u0434\u0438\u0442\u044c \u0441\u043b\u043e\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439 \u043d\u0435\u0442. \u0414\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438 \u0438 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u043b\u0443\u0447\u0448\u0435 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043d\u0435 \u043b\u0435\u043d\u0438\u0442\u044c\u0441\u044f. \u042f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u043c\u043e\u0435\u043c \u043e\u043f\u044b\u0442\u0435 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 DDD, \u041f\u043e\u0440\u0442\u043e\u0432 \u0438 \u0410\u0434\u0430\u043f\u0442\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u043e\u0431\u043e\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432. \u0415\u0441\u0442\u044c \u043a\u0440\u0430\u0442\u043a\u043e \u0441\u0443\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438: \u0414\u0436\u0443\u043d \u2014 \u043f\u0438\u0448\u0435\u0442 \u043a\u043e\u0434 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435. \u041c\u0438\u0434\u043b \u2014 \u043f\u0438\u0448\u0435\u0442 \u043a\u0443\u0447\u0443 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439. \u0421\u0435\u043d\u044c\u043e\u0440 \u2014 \u0437\u043d\u0430\u0435\u0442 \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435, \u0430 \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u044b \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438.<\/p>\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-300513","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/300513","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=300513"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/300513\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=300513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=300513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=300513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}