{"id":307030,"date":"2020-07-16T09:00:44","date_gmt":"2020-07-16T09:00:44","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=307030"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=307030","title":{"rendered":"\u0421\u043a\u0432\u043e\u0437\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u0435\u0440\u0442\u043a\u0438"},"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\/511190\/\">\u041f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043c\u044b \u043d\u0435 \u0440\u0435\u0434\u043a\u043e \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0441 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0435\u0439, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043b\u043e\u0433\u0438, \u0430\u0443\u0434\u0438\u0442\u044b, \u0440\u0430\u0437\u043e\u0441\u043b\u0430\u0442\u044c \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u044f. \u0412 \u043e\u0431\u0449\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043a\u0432\u043e\u0437\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b.<br \/>  \u041a\u043e\u0433\u0434\u0430 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435, \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u043e\u0431\u043e \u043d\u0435 \u0443\u0441\u0435\u0440\u0434\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0438 \u0432\u0441\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u044f\u043c\u043e \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445. \u041f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e, \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043e\u0431\u0440\u0430\u0441\u0442\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u043c\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0411\u041b \u0438 \u0441\u043a\u0432\u043e\u0437\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430. \u0410 \u044d\u0442\u043e \u0443\u0436\u0435 ILogger, IAuditService, INotifiesSerice.<br \/>  \u041d\u0435 \u0437\u043d\u0430\u044e \u043a\u0430\u043a \u0412\u044b, \u0430 \u044f \u043d\u0435 \u043b\u044e\u0431\u043b\u044e \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0439 \u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u043c\u043d\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0437\u0430 \u0440\u0430\u0437.<\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u043d\u0430\u043a\u0440\u0443\u0442\u0438\u0442\u044c \u043d\u0430 \u043a\u043e\u0434 \u043a\u0430\u043a\u0443\u044e \u043b\u0438\u0431\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0410\u041e\u041f. \u0412 \u0441\u0442\u0435\u043a\u0435 .NET \u0442\u0430\u043a\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0435\u043b\u0430\u044e\u0442 \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0438 \u0432 \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u043d\u0443\u0436\u043d\u044b\u0435 \u043c\u0435\u0441\u0442\u0430, \u0432\u043d\u0435\u0448\u043d\u0435 \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 \u043c\u0430\u0433\u0438\u044e 80 \u0443\u0440\u043e\u0432\u043d\u044f \u0438, \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e, \u0438\u043c\u0435\u044e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u043e\u0439.<\/p>\n<p>  \u042f \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u0437\u043e\u043b\u043e\u0442\u0443\u044e \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0443. \u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0435 \u043e\u0431\u043e\u0448\u043b\u0438 \u0432\u0430\u0441 \u0441\u0442\u043e\u0440\u043e\u043d\u043e\u0439, \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 \/>  \u0421\u043f\u043e\u0439\u043b\u0435\u0440. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043c\u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0440\u0435\u0448\u0438\u0442\u044c \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u0447\u0435\u043c \u044f \u043e\u043f\u0438\u0441\u0430\u043b \u0432\u044b\u0448\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044f \u043c\u043e\u0433\u0443 \u043e\u0442\u0434\u0430\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0411\u041b \u043e\u0434\u043d\u043e\u043c\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443, \u0430 \u043d\u0430\u0432\u0435\u0448\u0438\u0432\u0430\u043d\u0438\u0435 \u0441\u043a\u0432\u043e\u0437\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0438 \u0434\u0430\u0436\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u0434\u0440\u0443\u0433\u043e\u043c\u0443 <b>\u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e<\/b>.<\/p>\n<p>  \u0418 \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u043c\u043d\u0435 \u0432 \u044d\u0442\u043e\u043c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u0438 \u043d\u0430\u0434\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043d\u0430\u0434 DI. \u041a\u0442\u043e-\u0442\u043e \u0434\u0430\u043b\u0435\u0435 \u0441\u043a\u0430\u0436\u0435\u0442, \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u0440\u043e\u043a\u0441\u0438, \u0441 \u0440\u0430\u0434\u043e\u0441\u0442\u044c\u044e \u043e\u0431\u0441\u0443\u0436\u0443 \u044d\u0442\u043e \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0445.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0447\u0442\u043e \u044f \u0445\u043e\u0447\u0443 \u043a\u0430\u043a \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a?  <\/p>\n<ul>\n<li>\u041f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0411\u041b \u043d\u0435 \u043e\u0442\u0432\u043b\u0435\u043a\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043b\u0435\u0432\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b.<\/li>\n<li>\u0418\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432 \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u0430\u0445 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0411\u041b. \u041f\u0440\u0438\u0447\u0435\u043c \u044f \u043d\u0435 \u043b\u044e\u0431\u043b\u044e \u0434\u0435\u043b\u0430\u0442\u044c 100500 \u043c\u043e\u043a\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u0435\u0441\u044c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b. 2-3 \u2014 \u0435\u0449\u0435 \u043b\u0430\u0434\u043d\u043e, \u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0445\u043e\u0447\u0443.<\/li>\n<li>\u041f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043d\u0435 \u0438\u043c\u0435\u044f 7 \u043f\u044f\u0434\u0435\u0439 \u0432\u043e \u043b\u0431\u0443. \ud83d\ude42<\/li>\n<li>\u0418\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u043a\u0430\u0436\u0434\u043e\u0439 \u0435\u0433\u043e \u043e\u0431\u0435\u0440\u0442\u043a\u0438 <b>\u041e\u0422\u0414\u0415\u041b\u042c\u041d\u041e!<\/b><\/li>\n<\/ul>\n<p>  \u0427\u0442\u043e \u044f \u0445\u043e\u0447\u0443, \u043a\u0430\u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0438 \u043b\u0438\u0434\u0435\u0440 \u043a\u043e\u043c\u0430\u043d\u0434\u044b?  <\/p>\n<ul>\n<li>\u0418\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0438 \u0441 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0441\u0432\u044f\u0437\u043d\u043e\u0441\u0442\u044c\u044e, \u0447\u0442\u043e\u0431\u044b \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0442\u0440\u0430\u0442\u0438\u043b\u0438 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 (\u0435\u0441\u043b\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 \u043d\u0430\u0434\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0411\u041b, \u0430 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0434\u0443\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0438 \u043a\u0430\u043a \u0437\u0430\u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043e\u043d \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435. \u0418 \u0442\u0430\u043a \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u043a\u0443\u0441\u043a\u043e\u043c \u0411\u041b. \u041a\u0443\u0434\u0430 \u043f\u0440\u043e\u0449\u0435 \u0432\u0437\u044f\u0442\u044c\u0441\u044f \u0437\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 \u0430\u0443\u0434\u0438\u0442\u043e\u0432 \u0438 \u0440\u0430\u0441\u043f\u0438\u0445\u0430\u0442\u044c \u0438\u0445 \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0443).<\/li>\n<li>\u041e\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u0442 \u0435\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/li>\n<\/ul>\n<p>  \u041f\u043e\u043c\u043e\u0436\u0435\u0442 \u043c\u043d\u0435 \u0432 \u044d\u0442\u043e\u043c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441.  <\/p>\n<pre><code class=\"cs\">    \/\/\/ &lt;summary&gt;     \/\/\/     \u041e\u0431\u0435\u0440\u0442\u043a\u0430 \u0434\u043b\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430.     \/\/\/ &lt;\/summary&gt;     \/\/\/ &lt;typeparam name=&quot;T&quot;&gt; \u041a\u043b\u0430\u0441\u0441 \u0441\u0435\u0440\u0432\u0438\u0441\u0430. &lt;\/typeparam&gt;     public interface IDecorator&lt;T&gt;     {         \/\/\/ &lt;summary&gt;         \/\/\/     \u0414\u0435\u043b\u0435\u0433\u0430\u0442 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430.         \/\/\/ &lt;\/summary&gt;         Func&lt;T&gt; NextDelegate { get; set; }     }<\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0442\u043e \u0442\u0430\u043a<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">interface IService {     Response Method(Request request); }  class Service : IService {     public Response Method(Request request)     {         \/\/ BL     } }  class Wrapper : IDecorator&lt;IService&gt;, IService {     public Func&lt;IService&gt; NextDelegate { get; set; }      public Response Method(Request request)     {         \/\/ code before         var result = NextDelegate().Method(request);         \/\/ code after         return result;     } }<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0443\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u0443. <br \/>  <code>wrapper1<br \/>   wrapper2<br \/>   service<br \/>   end wrapper2<br \/>  end wrapper1<\/code><\/p>\n<p>  \u041d\u043e, \u043f\u043e\u0441\u0442\u043e\u0439\u0442\u0435. \u042d\u0442\u043e \u0436\u0435 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432 \u041e\u041e\u041f \u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435. \ud83d\ude00<\/p>\n<pre><code class=\"cs\">class Service {} class Wrapper1: Service {} class Wrapper2: Wrapper1 {}<\/code><\/pre>\n<p>  \u042f \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043b, \u0447\u0442\u043e \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u043a\u0432\u043e\u0437\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u0432 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0443 \u0438\u043b\u0438 \u043c\u0435\u043d\u044f\u0442\u044c \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u0443\u0436\u0435 \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f, \u0442\u0430\u043a \u0443 \u043c\u0435\u043d\u044f \u043d\u0430 \u0441\u043f\u0438\u043d\u0435 \u0432\u043e\u043b\u043e\u0441\u044b \u0434\u044b\u0431\u043e\u043c \u0432\u0441\u0442\u0430\u043b\u0438. <br \/>  \u041d\u043e \u043c\u043e\u044f \u043b\u0435\u043d\u044c \u2014 \u044d\u0442\u043e \u043d\u0435 \u0443\u0432\u0430\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430. \u0423\u0432\u0430\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0431\u0443\u0434\u0443\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u0440\u0438 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u043c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0432 \u043a\u043b\u0430\u0441\u0441\u0430\u0445 Wrapper1 \u0438 Wrapper2, \u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u0432 \u043c\u043e\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 NextDelegate \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043c\u043e\u043a\u0430\u0442\u044c. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u0431\u0435\u0440\u0442\u043a\u0438 \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043d\u0436\u0435\u043a\u0442\u044f\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u043f\u0440\u0438 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u043e\u0431\u0435\u0440\u0442\u043a\u0430 \u043e\u0431\u044f\u0437\u0430\u043d\u0430 \u0438\u043c\u0435\u0442\u044c <b>\u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435<\/b> \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0438\u0445 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f\u043c.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u0440\u0438\u043d\u044f\u0442, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c, \u0433\u0434\u0435, \u043a\u0430\u043a \u0438 \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0442\u044c NextDelegate.<\/p>\n<p>  \u042f \u0440\u0435\u0448\u0438\u043b, \u0447\u0442\u043e \u0441\u0430\u043c\u044b\u043c \u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0442\u0430\u043c, \u0433\u0434\u0435 \u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u044e \u0441\u0435\u0440\u0432\u0438\u0441\u044b. (Startup.sc, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e).<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0412\u043e\u0442 \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432 \u0431\u0430\u0437\u043e\u0432\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">            services.AddScoped&lt;Service&gt;();             services.AddTransient&lt;Wrapper1&gt;();             services.AddSingleton&lt;Wrapper2&gt;();             services.AddSingleton&lt;IService&gt;(sp =&gt;             {                 var wrapper2 = sp.GetService&lt;Wrapper2&gt;();                 wrapper2.NextDelegate = () =&gt;                 {                     var wrapper1 = sp.GetService&lt;Wrapper1&gt;();                     wrapper1.NextDelegate = () =&gt;                     {                         return sp.GetService&lt;Service&gt;();                     };                      return wrapper1;                 };                  return wrapper2;             });<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0412 \u0446\u0435\u043b\u043e\u043c, \u0432\u0441\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b, \u043d\u043e \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0434\u0440\u0443\u0433\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u2014 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>  \u042d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u043e\u043c \u0438\u043b\u0438 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0435\u0439. \u041d\u043e \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c. \u0412\u043d\u0435\u0448\u043d\u0435 \u0432\u0441\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0412\u043e\u0442 \u0447\u0435\u0433\u043e \u043c\u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">            services.AddDecoratedScoped&lt;IService, Service&gt;(builder =&gt;             {                 builder.AddSingletonDecorator&lt;Wrapper1&gt;();                 builder.AddTransientDecorator&lt;Wrapper2&gt;();                 builder.AddScopedDecorator&lt;Wrapper3&gt;();             });<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0410 \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u043c\u043d\u0435 \u0432 \u044d\u0442\u043e\u043c \u0432\u043e\u0442 \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0410 \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u043c\u043d\u0435 \u0432 \u044d\u0442\u043e\u043c \u0432\u043e\u0442 \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">    \/\/\/ &lt;summary&gt;     \/\/\/     \u041c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432.     \/\/\/ &lt;\/summary&gt;     public static class DecorationExtensions     {         \/\/\/ &lt;summary&gt;         \/\/\/     \u041c\u0435\u0442\u043e\u0434 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430.         \/\/\/ &lt;\/summary&gt;         \/\/\/ &lt;typeparam name=&quot;TDefinition&quot;&gt; \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u0435\u0440\u0432\u0438\u0441\u0430. &lt;\/typeparam&gt;         \/\/\/ &lt;typeparam name=&quot;TImplementation&quot;&gt; \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430. &lt;\/typeparam&gt;         \/\/\/ &lt;param name=&quot;lifeTime&quot;&gt;&lt;\/param&gt;         \/\/\/ &lt;param name=&quot;serviceCollection&quot;&gt; \u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432. &lt;\/param&gt;         \/\/\/ &lt;param name=&quot;decorationBuilder&quot;&gt; \u041f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c \u0434\u0435\u043a\u043e\u0440\u0430\u0446\u0438\u0439. &lt;\/param&gt;         \/\/\/ &lt;returns&gt; \u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432. &lt;\/returns&gt;         public static IServiceCollection AddDecorated&lt;TDefinition, TImplementation&gt;(             this IServiceCollection serviceCollection, ServiceLifetime lifeTime,             Action&lt;DecorationBuilder&lt;TDefinition&gt;&gt; decorationBuilder)             where TImplementation : TDefinition         {             var builder = new DecorationBuilder&lt;TDefinition&gt;();             decorationBuilder(builder);              var types = builder.ServiceDescriptors.Select(k =&gt; k.ImplementationType).ToArray();              var serviceDescriptor = new ServiceDescriptor(typeof(TImplementation), typeof(TImplementation), lifeTime);              serviceCollection.Add(serviceDescriptor);              foreach (var descriptor in builder.ServiceDescriptors)             {                 serviceCollection.Add(descriptor);             }              var resultDescriptor = new ServiceDescriptor(typeof(TDefinition),                 ConstructServiceFactory&lt;TDefinition&gt;(typeof(TImplementation), types), ServiceLifetime.Transient);             serviceCollection.Add(resultDescriptor);              return serviceCollection;         }          \/\/\/ &lt;summary&gt;         \/\/\/     \u041c\u0435\u0442\u043e\u0434 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438 Scoped.         \/\/\/ &lt;\/summary&gt;         \/\/\/ &lt;typeparam name=&quot;TDefinition&quot;&gt; \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u0435\u0440\u0432\u0438\u0441\u0430. &lt;\/typeparam&gt;         \/\/\/ &lt;typeparam name=&quot;TImplementation&quot;&gt; \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430. &lt;\/typeparam&gt;         \/\/\/ &lt;param name=&quot;serviceCollection&quot;&gt; \u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432. &lt;\/param&gt;         \/\/\/ &lt;param name=&quot;decorationBuilder&quot;&gt; \u041f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c \u0434\u0435\u043a\u043e\u0440\u0430\u0446\u0438\u0439. &lt;\/param&gt;         \/\/\/ &lt;returns&gt; \u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432. &lt;\/returns&gt;         public static IServiceCollection AddDecoratedScoped&lt;TDefinition, TImplementation&gt;(             this IServiceCollection serviceCollection,             Action&lt;DecorationBuilder&lt;TDefinition&gt;&gt; decorationBuilder)             where TImplementation : TDefinition         {             return serviceCollection.AddDecorated&lt;TDefinition, TImplementation&gt;(ServiceLifetime.Scoped,                 decorationBuilder);         }          \/\/\/ &lt;summary&gt;         \/\/\/     \u041c\u0435\u0442\u043e\u0434 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438 Singleton.         \/\/\/ &lt;\/summary&gt;         \/\/\/ &lt;typeparam name=&quot;TDefinition&quot;&gt; \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u0435\u0440\u0432\u0438\u0441\u0430. &lt;\/typeparam&gt;         \/\/\/ &lt;typeparam name=&quot;TImplementation&quot;&gt; \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430. &lt;\/typeparam&gt;         \/\/\/ &lt;param name=&quot;serviceCollection&quot;&gt; \u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432. &lt;\/param&gt;         \/\/\/ &lt;param name=&quot;decorationBuilder&quot;&gt; \u041f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c \u0434\u0435\u043a\u043e\u0440\u0430\u0446\u0438\u0439. &lt;\/param&gt;         \/\/\/ &lt;returns&gt; \u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432. &lt;\/returns&gt;         public static IServiceCollection AddDecoratedSingleton&lt;TDefinition, TImplementation&gt;(             this IServiceCollection serviceCollection,             Action&lt;DecorationBuilder&lt;TDefinition&gt;&gt; decorationBuilder)             where TImplementation : TDefinition         {             return serviceCollection.AddDecorated&lt;TDefinition, TImplementation&gt;(ServiceLifetime.Singleton,                 decorationBuilder);         }          \/\/\/ &lt;summary&gt;         \/\/\/     \u041c\u0435\u0442\u043e\u0434 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438 Transient.         \/\/\/ &lt;\/summary&gt;         \/\/\/ &lt;typeparam name=&quot;TDefinition&quot;&gt; \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u0435\u0440\u0432\u0438\u0441\u0430. &lt;\/typeparam&gt;         \/\/\/ &lt;typeparam name=&quot;TImplementation&quot;&gt; \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430. &lt;\/typeparam&gt;         \/\/\/ &lt;param name=&quot;serviceCollection&quot;&gt; \u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432. &lt;\/param&gt;         \/\/\/ &lt;param name=&quot;decorationBuilder&quot;&gt; \u041f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c \u0434\u0435\u043a\u043e\u0440\u0430\u0446\u0438\u0439. &lt;\/param&gt;         \/\/\/ &lt;returns&gt; \u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u043f\u043e\u0441\u043b\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432. &lt;\/returns&gt;         public static IServiceCollection AddDecoratedTransient&lt;TDefinition, TImplementation&gt;(             this IServiceCollection serviceCollection,             Action&lt;DecorationBuilder&lt;TDefinition&gt;&gt; decorationBuilder)             where TImplementation : TDefinition         {             return serviceCollection.AddDecorated&lt;TDefinition, TImplementation&gt;(ServiceLifetime.Transient,                 decorationBuilder);         }          \/\/\/ &lt;summary&gt;         \/\/\/     \u041c\u0435\u0442\u043e\u0434         \/\/\/ &lt;\/summary&gt;         \/\/\/ &lt;typeparam name=&quot;TService&quot;&gt;&lt;\/typeparam&gt;         \/\/\/ &lt;param name=&quot;implType&quot;&gt;&lt;\/param&gt;         \/\/\/ &lt;param name=&quot;next&quot;&gt;&lt;\/param&gt;         \/\/\/ &lt;returns&gt;&lt;\/returns&gt;         private static Func&lt;IServiceProvider, TService&gt; ConstructDecorationActivation&lt;TService&gt;(Type implType,             Func&lt;IServiceProvider, TService&gt; next)         {             return x =&gt;             {                 var service = (TService) x.GetService(implType);                  if (service is IDecorator&lt;TService&gt; decorator)                     decorator.NextDelegate = () =&gt; next(x);                 else                     throw new InvalidOperationException(&quot;\u041e\u0436\u0438\u0434\u0430\u043b\u0441\u044f \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440&quot;);                  return service;             };         }          \/\/\/ &lt;summary&gt;         \/\/\/     \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0430\u0431\u0440\u0438\u043a\u0438 \u0434\u043b\u044f \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430.         \/\/\/ &lt;\/summary&gt;         \/\/\/ &lt;typeparam name=&quot;TDefinition&quot;&gt; \u0422\u0438\u043f \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u0430. &lt;\/typeparam&gt;         \/\/\/ &lt;param name=&quot;serviceType&quot;&gt; \u0422\u0438\u043f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430. &lt;\/param&gt;         \/\/\/ &lt;param name=&quot;decoratorTypes&quot;&gt; \u0422\u0438\u043f\u044b \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043e\u0432 \u0432 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435. &lt;\/param&gt;         \/\/\/ &lt;returns&gt; \u0424\u0430\u0431\u0440\u0438\u043a\u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0447\u0435\u0440\u0435\u0437 DI. &lt;\/returns&gt;         private static Func&lt;IServiceProvider, object&gt; ConstructServiceFactory&lt;TDefinition&gt;(Type serviceType,             Type[] decoratorTypes)         {             return sp =&gt;             {                 Func&lt;IServiceProvider, TDefinition&gt; currentFunc = x =&gt;                     (TDefinition) x.GetService(serviceType);                 foreach (var decorator in decoratorTypes)                 {                     currentFunc = ConstructDecorationActivation(decorator, currentFunc);                 }                  return currentFunc(sp);             };         }     }<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u0430\u0445\u0430\u0440\u0430 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u0449\u0438\u043a\u043e\u0432<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u0430\u0445\u0430\u0440\u0430 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u0449\u0438\u043a\u043e\u0432<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">    \/\/\/ &lt;summary&gt;     \/\/\/     \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430.     \/\/\/ &lt;\/summary&gt;     \/\/\/ &lt;typeparam name=&quot;T&quot;&gt; \u0422\u0438\u043f \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430. &lt;\/typeparam&gt;     public class DecoratorBase&lt;T&gt; : IDecorator&lt;T&gt;     {         \/\/\/ &lt;summary&gt;         \/\/\/     \u0414\u0435\u043b\u0435\u0433\u0430\u0442 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 \u0438\u043b\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430.         \/\/\/ &lt;\/summary&gt;         public Func&lt;T&gt; NextDelegate { get; set; }          \/\/\/ &lt;summary&gt;         \/\/\/     \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u0434 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 \u0441 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430.         \/\/\/ &lt;\/summary&gt;         \/\/\/ &lt;typeparam name=&quot;TResult&quot;&gt; \u0422\u0438\u043f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. &lt;\/typeparam&gt;         \/\/\/ &lt;param name=&quot;lambda&quot;&gt; \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u043a\u043e\u0434. &lt;\/param&gt;         \/\/\/ &lt;returns&gt;&lt;\/returns&gt;         protected Task&lt;TResult&gt; ExecuteAsync&lt;TResult&gt;(Func&lt;T, Task&lt;TResult&gt;&gt; lambda)         {             return lambda(NextDelegate());         }          \/\/\/ &lt;summary&gt;         \/\/\/     \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u0434 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 \u0441 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430.         \/\/\/ &lt;\/summary&gt;         \/\/\/ &lt;param name=&quot;lambda&quot;&gt; \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u043a\u043e\u0434. &lt;\/param&gt;         \/\/\/ &lt;returns&gt;&lt;\/returns&gt;         protected Task ExecuteAsync(Func&lt;T, Task&gt; lambda)         {             return lambda(NextDelegate());         }     }<\/code><\/pre>\n<p>  \u0418\u043c\u0435\u044f \u0442\u0430\u043a\u043e\u0439 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0432 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u0433\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u043a \u0442\u043e \u0442\u0430\u043a<\/p>\n<pre><code class=\"cs\">    public Task&lt;Response&gt; MethodAsync(Request request)     {         return ExecuteAsync(async next =&gt;         {             \/\/ code before             var result = await next.MethodAsync(request);             \/\/ code after             return result;         });     }<\/code><\/pre>\n<p>  \u0410 \u0435\u0441\u043b\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u043d\u0430\u0434\u043e \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a<\/p>\n<pre><code class=\"cs\">    public Task&lt;Response&gt; MethodAsync(Request request)     {         return ExecuteAsync(next =&gt; next.MethodAsync(request));     }<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0430\u0433\u0438\u0438 \u0432\u0441\u0435 \u0436\u0435 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e \u2014 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 NextDelegate. \u0421\u0445\u043e\u0434\u0443 \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e \u0438 \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u043d\u043e \u043e\u043f\u044b\u0442\u043d\u044b\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u043d\u0430\u0439\u0434\u0435\u0442, \u0430 \u043d\u0435\u043e\u043f\u044b\u0442\u043d\u043e\u043c\u0443 \u043d\u0430\u0434\u043e 1 \u0440\u0430\u0437 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c. \u042d\u0442\u043e \u043a\u0430\u043a DbSet&#8217;\u044b \u0432 DbContext \ud83d\ude42<\/p>\n<p>  \u042f \u043d\u0435 \u0432\u044b\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u043b \u044d\u0442\u043e \u043d\u0430 \u0433\u0438\u0442 \u0445\u0430\u0431. \u041a\u043e\u0434\u0430 \u043d\u0435\u043c\u043d\u043e\u0433\u043e, \u043e\u043d \u0443\u0436\u0435 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0439, \u0442\u0430\u043a \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u0440\u0433\u0430\u0442\u044c \u043f\u0440\u044f\u043c\u043e \u043e\u0442\u0441\u044e\u0434\u0430.<\/p>\n<p>  \u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0445\u043e\u0447\u0443 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \ud83d\ude42<\/p><\/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\/511190\/\"> https:\/\/habr.com\/ru\/post\/511190\/<\/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\/511190\/\">\u041f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043c\u044b \u043d\u0435 \u0440\u0435\u0434\u043a\u043e \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0441 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0435\u0439, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043b\u043e\u0433\u0438, \u0430\u0443\u0434\u0438\u0442\u044b, \u0440\u0430\u0437\u043e\u0441\u043b\u0430\u0442\u044c \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u044f. \u0412 \u043e\u0431\u0449\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043a\u0432\u043e\u0437\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b.<br \/>  \u041a\u043e\u0433\u0434\u0430 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435, \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u043e\u0431\u043e \u043d\u0435 \u0443\u0441\u0435\u0440\u0434\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0438 \u0432\u0441\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u044f\u043c\u043e \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445. \u041f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e, \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043e\u0431\u0440\u0430\u0441\u0442\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u043c\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0411\u041b \u0438 \u0441\u043a\u0432\u043e\u0437\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430. \u0410 \u044d\u0442\u043e \u0443\u0436\u0435 ILogger, IAuditService, INotifiesSerice.<br \/>  \u041d\u0435 \u0437\u043d\u0430\u044e \u043a\u0430\u043a \u0412\u044b, \u0430 \u044f \u043d\u0435 \u043b\u044e\u0431\u043b\u044e \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0439 \u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u043c\u043d\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0437\u0430 \u0440\u0430\u0437.<\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u043d\u0430\u043a\u0440\u0443\u0442\u0438\u0442\u044c \u043d\u0430 \u043a\u043e\u0434 \u043a\u0430\u043a\u0443\u044e \u043b\u0438\u0431\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0410\u041e\u041f. \u0412 \u0441\u0442\u0435\u043a\u0435 .NET \u0442\u0430\u043a\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0435\u043b\u0430\u044e\u0442 \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0438 \u0432 \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u043d\u0443\u0436\u043d\u044b\u0435 \u043c\u0435\u0441\u0442\u0430, \u0432\u043d\u0435\u0448\u043d\u0435 \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 \u043c\u0430\u0433\u0438\u044e 80 \u0443\u0440\u043e\u0432\u043d\u044f \u0438, \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e, \u0438\u043c\u0435\u044e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u043e\u0439.<\/p>\n<p>  \u042f \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u0437\u043e\u043b\u043e\u0442\u0443\u044e \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0443. \u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0435 \u043e\u0431\u043e\u0448\u043b\u0438 \u0432\u0430\u0441 \u0441\u0442\u043e\u0440\u043e\u043d\u043e\u0439, \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-307030","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/307030","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=307030"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/307030\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=307030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=307030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=307030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}