{"id":294010,"date":"2019-08-29T15:01:06","date_gmt":"2019-08-29T15:01:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=294010"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=294010","title":{"rendered":"\u041a\u0430\u043a\u043e\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 Dependency Injection \u043e\u0442 Service Locator?"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<blockquote><p>\u0425\u0430, \u043a\u0430\u043a\u0430\u044f \u0438\u0437\u044f\u0449\u043d\u0430\u044f \u043c\u0430\u0441\u043a\u0438\u0440\u043e\u0432\u043a\u0430 Service Locator-\u0430 \u043f\u043e\u0434 DI. \u0414\u0430\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e DI! \ud83d\ude42<\/p><\/blockquote>\n<p>\u042d\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u043a\u043e\u043c\u043c\u0435\u043d\u0442 \u043a \u043c\u043e\u0435\u0439 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 &#171;<a href=\"https:\/\/habr.com\/ru\/post\/464347\/\">Dependency Injection, JavaScript \u0438 ES6-\u043c\u043e\u0434\u0443\u043b\u0438<\/a>&#171;. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u043a\u043e\u043b\u043b\u0435\u0433\u0435 <a href=\"https:\/\/habr.com\/ru\/users\/symbix\/\" class=\"user_link\">symbix<\/a> &#8216;\u0443 \u0437\u0430 \u044d\u0442\u043e\u0442 \u043a\u043e\u043c\u043c\u0435\u043d\u0442, \u0442.\u043a. \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d \u0441\u0442\u0430\u043b\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u043e\u0439 \u043f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0432 \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u0438 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0442 \u0434\u0440\u0443\u0433\u043e\u0433\u043e. \u041f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u043c\u043e\u0439 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/v3\/8k\/ax\/v38kaxu_rzz_k0hweljvwl5n6vi.jpeg\" alt=\"image\"><\/p>\n<p>  <\/p>\n<p><em>(\u041a\u0414\u041f\u0412 \u043e\u0441\u043e\u0431\u043e\u0433\u043e \u0441\u043c\u044b\u0441\u043b\u0430 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0438 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043f\u043e\u0437\u043d\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 \u0440\u044f\u0434\u0443 \u0434\u0440\u0443\u0433\u0438\u0445)<\/em><\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438 (<em>\u0447\u0430\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043a\u043e\u0434\u0430 \u044f \u0431\u0443\u0434\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0430 PHP, \u0447\u0430\u0441\u0442\u044c \u043d\u0430 JS, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u0442\u0438 \u0434\u0432\u0430 \u044f\u0437\u044b\u043a\u0430 \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043c\u043e\u0451\u043c \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c \u0431\u0430\u0433\u0430\u0436\u0435, \u0430 \u0447\u0430\u0441\u0442\u044c \u043d\u0430 \u043b\u044e\u0431\u043e\u043c \u0434\u0440\u0443\u0433\u043e\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044f \u0441\u043f\u0451\u0440 \u044d\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430<\/em>).<\/p>\n<p>  <\/p>\n<h1 id=\"dependency-injection\">Dependency Injection<\/h1>\n<p>  <\/p>\n<blockquote><p>DI \u0436\u0435 \u0432 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445 \u2014 \u0432\u043c\u0435\u0441\u0442\u043e require\/import \u043c\u043e\u0434\u0443\u043b\u044f \u0432\u044b \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u0442\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 (\u0438\u043b\u0438 \u0441\u0435\u0442\u0442\u0435\u0440 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430). \u0422\u043e \u0435\u0441\u0442\u044c \u0437\u0430 \u044d\u0442\u0438\u043c \u0433\u0440\u043e\u043c\u043a\u0438\u043c \u0441\u043b\u043e\u0432\u043e\u043c \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u00ab\u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u00bb.<\/p><\/blockquote>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u043c\u043c\u0435\u043d\u0442 \u043a\u043e\u043b\u043b\u0435\u0433\u0438 <a href=\"https:\/\/habr.com\/ru\/users\/risedphantom\/\" class=\"user_link\">risedphantom<\/a> &#8216;\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0442\u043e\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0441\u0443\u0442\u044c \u044f\u0432\u043b\u0435\u043d\u0438\u044f. \u0427\u0442\u043e\u0431\u044b \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442\u044c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u044f\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u2014 \u0432 \u0432\u0438\u0434\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 (\u043e\u0431\u044b\u0447\u043d\u043e, \u043d\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430):<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">class MainClass {     public function __construct($dep1, $dep2, $dep3) {} }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0441\u0451. DI \u2014 \u043e\u043d \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c. \u041d\u0443\u0436\u043d\u044b\u0435 \u043d\u0430\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u0435\u043c-\u0442\u043e \u0442\u0430\u043c. \u0410 \u0433\u0434\u0435 \u044d\u0442\u043e\u0442 &#171;\u043a\u0442\u043e-\u0442\u043e \u0442\u0430\u043c&#187; \u0438\u0445 \u0431\u0435\u0440\u0451\u0442 \u2014 DI \u044d\u0442\u043e \u043d\u0435 \u0432\u043e\u043b\u043d\u0443\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u043a\u043e\u0434\u0430 \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e &#171;\u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435&#187; \u0434\u043b\u044f \u043d\u0435\u0433\u043e (\u0438 \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043c\u0435\u043b\u043e \u043c\u0435\u043d\u044f\u0442\u044c), \u0430 \u0447\u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\/\u0443\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u0443 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u0412\u043e\u0442 \u044d\u0442\u043e \u0432\u043e\u043b\u043d\u0443\u0435\u0442 DI. \u041f\u043e\u0447\u0435\u043c\u0443 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c, \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u0430 \u043d\u0435 \u0432 setter&#8217;\u0430\u0445? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 \u0442\u0430\u043a \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u2014 \u043e\u043d \u0441\u0440\u0430\u0437\u0443 \u0432\u0438\u0434\u0438\u0442 \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435. \u041c\u044b \u043f\u0440\u0438\u0432\u044b\u043a\u043b\u0438 \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e DI \u2014 \u044d\u0442\u043e \u0447\u0442\u043e-\u0442\u043e \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043d\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438\/\u043c\u0435\u0442\u043e\u0434\u0430 \u2014 \u044d\u0442\u043e \u0432\u0435\u0434\u044c \u0442\u043e\u0436\u0435 DI:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">function f(dep1, dep2, dep3) {}<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a\u043e\u0439 \u043e\u0441\u043e\u0431\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u0434\u0440\u0443\u0433\u0438\u0445.<\/p>\n<p>  <\/p>\n<h1 id=\"service-locator\">Service Locator<\/h1>\n<p>  <\/p>\n<p>\u041b\u043e\u043a\u0430\u0442\u043e\u0440 \u0441\u043b\u0443\u0436\u0431 \u2014 \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u0430\u043d\u0442\u0438-\u0448\u0430\u0431\u043b\u043e\u043d. \u0410 \u0447\u0435\u043c \u043e\u043d \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f? \u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043e\u0434\u043d\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c. <a href=\"https:\/\/designpatternsphp.readthedocs.io\/ru\/latest\/More\/ServiceLocator\/README.html\">\u0412\u043e\u0442<\/a> \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0442\u0430\u043a\u043e\u0433\u043e \u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">interface ServiceLocator {     public function addInstance(string $class, Service $service);     public function addClass(string $class, array $params);     public function has(string $interface): bool;     public function get(string $class): Service; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041b\u043e\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b (\u0438\u043b\u0438 \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f) \u0438 \u0437\u0430\u0442\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u044d\u0442\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c. \u041b\u043e\u043a\u0430\u0442\u043e\u0440\u0443, \u043f\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u043c\u0443 \u0441\u0447\u0451\u0442\u0443, \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e, \u043a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432 \u043d\u0451\u043c \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u043e\u043d\u0438 \u0438\u0437\u0432\u043d\u0435 \u044f\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438 \u043f\u043e\u043c\u0435\u0449\u0435\u043d\u044b \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0441\u0430\u043c\u0438\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c.<\/p>\n<p>  <\/p>\n<p>\u041b\u043e\u043a\u0430\u0442\u043e\u0440 \u0441\u043b\u0443\u0436\u0431 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a \u043d\u0438\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0430. \u0412\u0441\u0451.<\/p>\n<p>  <\/p>\n<h1 id=\"dependency-injection-container\">Dependency Injection Container<\/h1>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440? \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e <a href=\"https:\/\/stackoverflow.com\/a\/50724263\/4073821\">\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0441\u043a\u0430\u0437\u0430<\/a> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e &#171;<a href=\"https:\/\/www.manning.com\/books\/dependency-injection-principles-practices-patterns\">Dependency Injection Principles, Practices, and Patterns<\/a>&#171;: <em>&#171;a software library that that provides DI functionality and allows automating many of the tasks involved in Object Composition, Interception, and Lifetime Management. DI Containers are also known as Inversion of Control (IoC) Containers. (\u00a73.2.2)&#187;<\/em><\/p>\n<p>  <\/p>\n<p>\u0422.\u0435., DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0430 \u043b\u0438\u0448\u044c \u0432\u043e \u0432\u0442\u043e\u0440\u0443\u044e \u2014 \u0437\u0430 \u0438\u0445 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435. \u0412 DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0435\u0441\u043b\u0438 \u0441\u0430\u043c\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0435 \u043d\u0443\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445, \u043e\u0431\u0449\u0438\u0445 \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u0442\u0438\u043f\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u043b\u043e\u0433\u0433\u0435\u0440\u0430).<\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 <a href=\"https:\/\/github.com\/symfony\/dependency-injection\/blob\/master\/ContainerInterface.php\">Symfony<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">interface ContainerInterface extends PsrContainerInterface {     public function set(string $id, ?object $service);     public function get($id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);     public function has($id);     public function initialized(string $id);     public function getParameter(string $name);     public function hasParameter(string $name);     public function setParameter(string $name, $value); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c \u0441\u0435\u0431\u044f, \u0447\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u041b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u0421\u043b\u0443\u0436\u0431 \u2014 \u0442\u0435 \u0436\u0435 \u0441\u0430\u043c\u044b\u0435 <code>get<\/code>, <code>has<\/code> \u0438 <code>set<\/code>\/<code>add<\/code>.<\/p>\n<p>  <\/p>\n<h1 id=\"chem-zhe-ploh-service-locator\">\u0427\u0435\u043c \u0436\u0435 \u043f\u043b\u043e\u0445 Service Locator?<\/h1>\n<p>  <\/p>\n<p>\u0410 \u043d\u0438\u0447\u0435\u043c. \u041f\u043b\u043e\u0445 \u043d\u0435 \u0441\u0430\u043c \u0448\u0430\u0431\u043b\u043e\u043d, \u0430 \u0442\u043e, \u043a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u043d \u0438\u043d\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0435\u0441\u0442\u044c <a href=\"https:\/\/habr.com\/ru\/post\/270005\/\">\u0442\u0430\u043a\u043e\u0435 \u043c\u043d\u0435\u043d\u0438\u0435<\/a>, \u0447\u0442\u043e &#171;<em>Service Locator \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u0442 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u044e \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043d\u0435\u0447\u0451\u0442\u043a\u043e \u0432\u044b\u0440\u0430\u0436\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u0443\u0441\u043b\u043e\u0432\u0438\u044f<\/em>&#171;. \u0418 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"vbscript\">public class OrderProcessor : IOrderProcessor {     public void Process(Order order)     {         var validator = Locator.Resolve&lt;IOrderValidator&gt;();         if (validator.Validate(order))         {             var shipper = Locator.Resolve&lt;IOrderShipper&gt;();             shipper.Ship(order);         }     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0438\u043f\u0430, \u0432\u043e\u0442 \u0442\u0430\u043a \u043f\u043b\u043e\u0445\u043e, \u0430 \u0445\u043e\u0440\u043e\u0448\u043e \u2014 \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"vbscript\">public class OrderProcessor : IOrderProcessor {     public OrderProcessor(IOrderValidator validator, IOrderShipper shipper)      public void Process(Order order) }<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0439, \u0434\u0430 \u043c\u044b \u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0432\u0435\u043b\u0438 \u0437\u0430 \u0441\u043a\u043e\u0431\u043a\u0438 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0430\u043c\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438 <code>IOrderValidator<\/code> \u0438 <code>IOrderShipper<\/code>! \u0412\u043f\u043e\u043b\u043d\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0433\u0434\u0435-\u0442\u043e \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"vbscript\">var validator = Locator.Resolve&lt;IOrderValidator&gt;(); var shipper = Locator.Resolve&lt;IOrderShipper&gt;(); var processor = new OrderProcessor(validator, shipper); processor.Process(order);<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"composition-root\">Composition Root<\/h1>\n<p>  <\/p>\n<p>\u0413\u043e\u0432\u043e\u0440\u044f \u043e \u0412\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0438 \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043d\u0435 \u043f\u0440\u0438\u0439\u0442\u0438 \u043a \u0442\u0430\u043a\u043e\u043c\u0443 \u043f\u043e\u043d\u044f\u0442\u0438\u044e, \u043a\u0430\u043a <a href=\"https:\/\/freecontent.manning.com\/dependency-injection-in-net-2nd-edition-understanding-the-composition-root\/\">Composition Root<\/a> (\u0434\u0430\u043b\u0435\u0435 \u044f \u0431\u0443\u0434\u0443 \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u044d\u0442\u043e &#171;\u0422\u043e\u0447\u043a\u0430 \u0421\u0431\u043e\u0440\u043a\u0438&#187;). \u042d\u0442\u043e \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 &#171;<em>\u043a\u0442\u043e-\u0442\u043e<\/em>&#171;, \u043a\u043e\u043c\u0443 \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043e\u0431\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0438 \u0438\u0445 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044e.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0422\u043e\u0447\u043a\u0435 \u0421\u0431\u043e\u0440\u043a\u0438 \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u044f\u0432\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0438 \u0432\u043d\u0435\u0434\u0440\u044f\u044e\u0442\u0441\u044f \u0442\u0443\u0434\u0430, \u0433\u0434\u0435 \u0438\u0445 \u0436\u0434\u0443\u0442. \u0417\u0434\u0435\u0441\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u041b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u043c \u0421\u043b\u0443\u0436\u0431 \u0438 DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b. \u0418 \u0442\u043e\u0442 \u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0445\u0440\u0430\u043d\u0438\u043c\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b. \u042f \u0431\u044b \u0434\u0430\u0436\u0435 \u0432\u0437\u044f\u043b\u0441\u044f \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043d\u0435\u0442.<\/p>\n<p>  <\/p>\n<h1 id=\"glavnoe-otlichie\">\u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>\u0410 \u0433\u0434\u0435 \u0436\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u043c\u0435\u0436\u0434\u0443 DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c \u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c \u041b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u0421\u043b\u0443\u0436\u0431 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u044f\u0432\u043d\u044b\u0435? \u0412 \u043b\u044e\u0431\u043e\u043c \u0434\u0440\u0443\u0433\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435 \u043a \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$obj = Container::getInstance()-&gt;get($objId);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u043e\u043d\u043e. \u0412 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435 \u0432 \u043b\u044e\u0431\u043e\u043c \u043c\u0435\u0441\u0442\u0435 (\u0435\u0441\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u043d\u0435 \u0422\u043e\u0447\u043a\u0430 \u0421\u0431\u043e\u0440\u043a\u0438, \u043d\u043e \u0438 \u0442\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0432\u0435\u0441\u044c\u043c\u0430 \u0441\u043e\u043c\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e) \u043b\u044e\u0431\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0430\u043d\u0442\u0438-\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u043c \u0441 \u0438\u043c\u0435\u043d\u0435\u043c Service Locator.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u043b\u043b\u0435\u0433\u0430 <a href=\"https:\/\/habr.com\/ru\/users\/volch\/\" class=\"user_link\">VolCh<\/a> \u043a\u0440\u0430\u0442\u043a\u043e \u0438 \u0451\u043c\u043a\u043e \u043e\u0442\u0432\u0435\u0442\u0438\u043b \u043d\u0430 \u043c\u043e\u0439 <a href=\"https:\/\/habr.com\/ru\/post\/464347\/#comment_20535581\">\u0432\u043e\u043f\u0440\u043e\u0441<\/a>:<\/p>\n<p>  <\/p>\n<blockquote><p>\u0410 \u0447\u0435\u043c, \u043f\u043e \u0432\u0430\u0448\u0435\u043c\u0443, true DI \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 Service Locator, \u0437\u0430\u043c\u0430\u0441\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434 DI?<\/p><\/blockquote>\n<p>\u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<blockquote><p>\u0414\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0443<\/p><\/blockquote>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438 \u0432\u0441\u044f \u044d\u0442\u0430 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0437\u0432\u0451\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0432\u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0435\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430.<\/p>\n<p>  <\/p>\n<h1 id=\"legalnoe-primenenie-konteynera\">\u041b\u0435\u0433\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u041a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430<\/h1>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u041a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c \u0438\u043b\u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c \u041b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u0421\u043b\u0443\u0436\u0431, \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0433\u0434\u0435 \u0438 \u043a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c. \u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u0441\u043a\u0430\u0437\u0430\u043b \u0432\u044b\u0448\u0435, \u0432 \u0422\u043e\u0447\u043a\u0435 \u0421\u0431\u043e\u0440\u043a\u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0442\u0438\u043f\u0430\u043c\u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432 \u0438\u0441\u0447\u0435\u0437\u0430\u0435\u0442. \u041d\u043e \u0447\u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c, \u0435\u0441\u043b\u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0441\u0430\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u0434\u043b\u044f \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u043a\u043b\u0430\u0441\u0441\u0430?<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">class Foo {     public function __construct(Container $container){} }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043f\u044f\u0442\u044c-\u0442\u0430\u043a\u0438, \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440. \u0412\u043e\u0442 \u0434\u0432\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043e\u0434\u0438\u043d \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0442\u043e\u0447\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0443 \u041b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u0421\u043b\u0443\u0436\u0431 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u043d\u0442\u0438-\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u043c, \u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432\u043e \u043d\u0430 \u0436\u0438\u0437\u043d\u044c \u043f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445.<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">class Foo {     private $dep;     public function __construct(Container $container)     {         $this-&gt;dep = $container-&gt;get('depId');     } }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"php\">class Foo {     private $container;     public function __construct(Container $container)     {         $this-&gt;container = $container;     }      public function initModules($modules) {         foreach ($modules as $initClassId) {             $init= $this-&gt;container-&gt;get($initClassId);             $init-&gt;exec();         }     } }<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"rezyume\">\u0420\u0435\u0437\u044e\u043c\u0435<\/h1>\n<p>  <\/p>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u0441\u0451 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435, DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u043b\u0430\u0434\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0448\u0438\u0440\u043e\u043a\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c, \u0447\u0435\u043c \u041b\u043e\u043a\u0430\u0442\u043e\u0440 \u0421\u043b\u0443\u0436\u0431, \u043d\u043e \u0441\u0443\u0442\u044c \u044d\u0442\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u0441\u0430\u043c\u044b\u0439 \u043d\u0430\u0432\u043e\u0440\u043e\u0447\u0435\u043d\u043d\u044b\u0439 DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043b\u0435\u043a\u0433\u043e \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u043a\u0430\u043a \u041b\u043e\u043a\u0430\u0442\u043e\u0440 \u0421\u043b\u0443\u0436\u0431, \u0430 \u0432\u043e\u0442 \u0447\u0442\u043e\u0431\u044b \u041b\u043e\u043a\u0430\u0442\u043e\u0440 \u0421\u043b\u0443\u0436\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u2014 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>P.S.<br \/>  \u043d\u0435 \u043c\u043e\u0433\u0443 \u043d\u0435 \u0434\u0430\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0431\u043b\u043e\u0433 &#171;<a href=\"http:\/\/sergeyteplyakov.blogspot.com\/\">Programming stuff<\/a>&#187; \u0421\u0435\u0440\u0433\u0435\u044f \u0422\u0435\u043f\u043b\u044f\u043a\u043e\u0432\u0430 \u2014 \u0443\u0436 \u043e\u0447\u0435\u043d\u044c \u0442\u0430\u043c \u0445\u043e\u0440\u043e\u0448\u043e <a href=\"http:\/\/sergeyteplyakov.blogspot.com\/search\/label\/%D0%A3%D0%BF%D1%80%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD%D0%B8%D0%B5%20%D0%B7%D0%B0%D0%B2%D0%B8%D1%81%D0%B8%D0%BC%D0%BE%D1%81%D1%82%D1%8F%D0%BC%D0%B8\">\u044d\u0442\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u044b<\/a> \u043e\u0441\u0432\u0435\u0449\u0435\u043d\u044b.<\/p>\n<\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \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\/465395\/\"> https:\/\/habr.com\/ru\/post\/465395\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<blockquote><p>\u0425\u0430, \u043a\u0430\u043a\u0430\u044f \u0438\u0437\u044f\u0449\u043d\u0430\u044f \u043c\u0430\u0441\u043a\u0438\u0440\u043e\u0432\u043a\u0430 Service Locator-\u0430 \u043f\u043e\u0434 DI. \u0414\u0430\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e DI! \ud83d\ude42<\/p><\/blockquote>\n<p>\u042d\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u043a\u043e\u043c\u043c\u0435\u043d\u0442 \u043a \u043c\u043e\u0435\u0439 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 &#171;<a href=\"https:\/\/habr.com\/ru\/post\/464347\/\">Dependency Injection, JavaScript \u0438 ES6-\u043c\u043e\u0434\u0443\u043b\u0438<\/a>&#171;. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u043a\u043e\u043b\u043b\u0435\u0433\u0435 <a href=\"https:\/\/habr.com\/ru\/users\/symbix\/\" class=\"user_link\">symbix<\/a> &#8216;\u0443 \u0437\u0430 \u044d\u0442\u043e\u0442 \u043a\u043e\u043c\u043c\u0435\u043d\u0442, \u0442.\u043a. \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d \u0441\u0442\u0430\u043b\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u043e\u0439 \u043f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0432 \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u0438 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0442 \u0434\u0440\u0443\u0433\u043e\u0433\u043e. \u041f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u043c\u043e\u0439 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/v3\/8k\/ax\/v38kaxu_rzz_k0hweljvwl5n6vi.jpeg\" alt=\"image\"><\/p>\n<p>  <\/p>\n<p><em>(\u041a\u0414\u041f\u0412 \u043e\u0441\u043e\u0431\u043e\u0433\u043e \u0441\u043c\u044b\u0441\u043b\u0430 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0438 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043f\u043e\u0437\u043d\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 \u0440\u044f\u0434\u0443 \u0434\u0440\u0443\u0433\u0438\u0445)<\/em><\/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-294010","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/294010","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=294010"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/294010\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=294010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=294010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=294010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}