{"id":303304,"date":"2020-05-09T21:00:49","date_gmt":"2020-05-09T21:00:49","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=303304"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=303304","title":{"rendered":"\u041a\u0440\u0430\u0442\u043a\u043e \u043e \u0442\u043e\u043c \u043a\u0443\u0434\u0430 \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c Repository \u0432 Onion Architeckture \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\/501206\/\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/g-\/md\/vn\/g-mdvngslazcpacsfe-hx_pbk-q.png\" width=\"400\"><\/div>\n<p>  \u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440. \u0425\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0442\u043e\u043c \u043a\u0443\u0434\u0430, \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u0432\u044b\u0448\u0435, \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439. \u0415\u0449\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e DI, IoC \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0442\u043e \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442. <br \/>  <a name=\"habracut\"><\/a><br \/>  1) Repository \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u0441 \u0411\u0414 \u044d\u0442\u043e InfrastructureService \u0442\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c EmailSender \u0438\u043b\u0438 EmailService, FileService (\u043e\u0431\u0435\u0440\u0442\u043a\u0430 \u043d\u0430\u0434 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 File.Open(\u2026 ) \u0438 \u0442. \u043f.) \u0438 \u043f\u0440\u043e\u0447\u0435\u0435 \u0432 \u044d\u0442\u043e\u043c \u0434\u0443\u0445\u0435. 2) Serivice \u044d\u0442\u043e \u043b\u044e\u0431\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0431\u0435\u0437 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. InfrastructureService \u044d\u0442\u043e \u0430\u043d\u0442\u0438 \u043a\u043e\u0440\u0440\u0430\u043f\u0448\u043d \u043b\u0430\u0435\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u043e\u043b\u0438\u0440\u0443\u0435\u0442 \u0432\u0430\u0441 \u043e\u0442 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b c SMTP \u043d\u0443 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043e\u0442 ORM \u0438\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0411\u0430\u0437\u043e\u0439 \u0414\u0430\u043d\u043d\u044b\u0445 \u0438 \u0442. \u043f. 3) Repository \u044d\u0442\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d. \u0415\u0433\u043e \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u043e\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0439 List \u044d\u0442\u043e Repository \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u043c\u0430\u0441\u0441\u0438\u0432 T[] \u0438 \u043f\u043e \u0441\u0443\u0442\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f ValueObject \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u044c\u0441\u044f \u043a \u0441\u043b\u043e\u044e Entities. \u041d\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d Repository \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f InfrastructureService \u0438 \u043d\u0435 \u0432\u0441\u0435 InfrastructureService \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d Repository. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: Logger, EmailSender. <\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u0443\u0434\u0430 \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u043d\u0430\u0434\u043e \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043f\u0440\u043e Dependency Inversion \u0438 Inversion of Control. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0438\u043c \u043d\u0430\u0448 ApplicationService \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Infrastructure \u043d\u0435 \u0437\u043d\u0430\u044e \u043f\u0440\u043e \u0442\u043e\u043c \u043a\u0430\u043a\u0430\u044f \u0443 \u043d\u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0442\u0430\u043a\u0438\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438 \u043a\u0430\u043a 1) \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c Infrastructure \u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u043d\u0438\u043c. 2) \u041f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u044b \u0432\u0440\u043e\u0434\u0435 Action \u0438 Func. <\/p>\n<p>  \u0427\u0435\u0440\u0435\u0437 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b:<\/p>\n<pre><code class=\"cs\">\/\/\u041d\u0430\u0448 InfrastructureService. \u0421\u0430\u043c\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432 \u0441\u043b\u043e\u0435 Infrastructure     interface IRepository     {         int Get();     }      class ApplicationService     {         private readonly IRepository _repository;          public ApplicationService(IRepository repository)         {             _repository = repository;         }          public int GetInt() =&gt; _repository.Get();     } <\/code><\/pre>\n<p>  \u0427\u0435\u0440\u0435\u0437 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u044b:<\/p>\n<pre><code class=\"cs\">    class ApplicationService     {         private readonly Func&lt;int&gt; _getIntFromDb;          public ApplicationService(Func&lt;int&gt; getIntFromDb)         {             _getIntFromDb = getIntFromDb;         }          public int GetInt() =&gt; _getIntFromDb();     } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e \u0442\u043e\u043c \u043a\u0430\u043a \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434. \u0422\u0443\u0442 \u043d\u0430\u0434\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0434\u0432\u0430 \u0441\u043b\u0443\u0447\u0430\u044f: 1) \u0412\u0441\u0435 \u0440\u0430\u0437\u0431\u0438\u0442\u043e \u043f\u043e \u043f\u0430\u043f\u043a\u0430\u043c. 2) \u0412\u0441\u0435 \u0440\u0430\u0437\u0431\u0438\u0442\u043e \u043f\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/habr.com\/ru\/post\/493426\/\">\u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0442\u0443\u0442<\/a>.<\/p>\n<h2>\u041f\u043e \u043f\u0430\u043f\u043a\u0430\u043c \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/h2>\n<p>  \u041f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 InfrastructureServices (Repository) \u0432 \u043f\u0430\u043f\u043a\u0443 Infrastructure. <\/p>\n<p>  <a href=\"https:\/\/github.com\/VictoremWinbringer\/SnakeGameWithOnionAkaCleanArchitecture\/\" rel=\"nofollow\">\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 <\/a><\/p>\n<p>  Game\/SnakeGame:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/4-\/5g\/aq\/4-5gaquzhbyyxsgpbcl9vnzdh2i.jpeg\"><\/p>\n<h2>\u041f\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c<\/h2>\n<p>  \u041f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b InfrastructureServices (IRepository) \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 ApplicationServices, \u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e (Repository) \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Infrastructure.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/fz\/5z\/vb\/fz5zvbdvpvwqvwq9fmce7v07i0g.jpeg\"><\/p>\n<h2>\u0412\u044b\u0432\u043e\u0434\u044b<\/h2>\n<p>  \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 (IRepository, IEmailSender) \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 ApplicationServices.dll, \u0430 \u0438\u0445 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e (Repository, EMailSender) \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Infrastructure.dll. \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c IRepository \u0432 Infrastructure.dll \u0438 \u0432\u0437\u044f\u0442\u044c \u043d\u0430 \u043d\u0435\u0433\u043e \u0441\u0441\u044b\u043b\u043a\u0443 \u0432 ApplicationServices.dll \u0442\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 IRepository \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043c \u0438 \u043d\u0443\u0436\u0435\u043d \u043a \u043d\u0430\u043c \u043f\u0440\u0438\u043b\u0435\u0442\u044f\u0442 \u0435\u0449\u0435 \u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 EntityFramework, SmtpClient \u0438 \u043f\u0440\u043e\u0447\u0435\u0435 \u0432 \u044d\u0442\u043e\u043c \u0434\u0443\u0445\u0435 \u043b\u0438\u0448\u043d\u0435\u0435.<\/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\/501206\/\"> https:\/\/habr.com\/ru\/post\/501206\/<\/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\/501206\/\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/g-\/md\/vn\/g-mdvngslazcpacsfe-hx_pbk-q.png\" width=\"400\"><\/div>\n<p>  \u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440. \u0425\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0442\u043e\u043c \u043a\u0443\u0434\u0430, \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u0432\u044b\u0448\u0435, \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439. \u0415\u0449\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e DI, IoC \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0442\u043e \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442.   <\/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-303304","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303304","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=303304"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303304\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=303304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=303304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=303304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}