{"id":217523,"date":"2014-04-01T00:47:03","date_gmt":"2014-03-31T20:47:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=217523"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=217523","title":{"rendered":"<span class=\"post_title\">\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043d\u0430 Dependency Injection. \u041f\u0443\u0442\u044c \u0421\u0438\u0442\u0445\u0430<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0412\u043d\u0435\u0441\u0443 \u0438 \u0441\u0432\u043e\u0439 \u0432\u043a\u043b\u0430\u0434 \u0432 \u0442\u0440\u0435\u043d\u0434 <a href=\"http:\/\/habrahabr.ru\/post\/192320\/\">\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/a>.<br \/>  \u041c\u043d\u043e\u0433\u0438\u043c \u0438\u0437 \u0432\u0430\u0441 \u0437\u043d\u0430\u043a\u043e\u043c\u0430 \u0434\u0438\u043b\u0435\u043c\u043c\u0430: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u0438 DI \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0438\u043b\u0438 \u043d\u0435\u0442.<br \/>  \u041f\u043e\u0432\u043e\u0434\u044b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043d\u0430 DI:<\/p>\n<ul>\n<li>\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0430\u0432\u0442\u043e-\u0442\u0435\u0441\u0442\u043e\u0432<\/li>\n<li>\u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445<\/li>\n<li>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 3rd-party \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u043d\u0430 DI<\/li>\n<li>\u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 DI<\/li>\n<\/ul>\n<p>\u0414\u043e\u0432\u043e\u0434\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c DI:<\/p>\n<ul>\n<li>\u0443\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 (\u043f\u043e\u043d\u0430\u0447\u0430\u043b\u0443)<\/li>\n<li>\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/li>\n<li>\u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 DI<\/li>\n<\/ul>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442, \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0430 DI. \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0447\u0443\u0432\u0441\u0442\u0432\u0443\u044e\u0442 \u0441\u0432\u043e\u0439 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b, \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043c\u0438\u0434\u0438\u0445\u043b\u043e\u0440\u0438\u0430\u043d \u0432 \u043a\u0440\u043e\u0432\u0438 \u0437\u0430\u0448\u043a\u0430\u043b\u0438\u0432\u0430\u0435\u0442.<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/cc6\/bdc\/711\/cc6bdc711f607edb74b597118a6794f9.jpg\" width=\"400\"\/><br \/>  <i>\u041f\u0443\u0442\u044c \u0442\u0435\u0431\u044f \u0436\u0434\u0435\u0442 \u0442\u0435\u0440\u043d\u0438\u0441\u0442\u044b\u0439 \u0438 \u0434\u043e\u043b\u0433\u0438\u0439, \u043c\u043e\u0439 \u044e\u043d\u044b\u0439 \u043f\u0430\u0434\u0430\u0432\u0430\u043d.<\/i><\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0438 \u0432 \u043d\u0435\u043c \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u043e\u0434\u043d\u0438\u043c \u043a\u043e\u043c\u043c\u0438\u0442\u043e\u043c \u0432\u0440\u044f\u0434 \u043b\u0438 \u0443\u0434\u0430\u0441\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043b\u043e\u0445\u0438\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u043a, \u0430 \u043f\u043e\u0442\u043e\u043c&#8230;<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h5>\u0421 \u0447\u0435\u0433\u043e \u043d\u0430\u0447\u0430\u0442\u044c<\/h5>\n<p>DI \u0438\u043c\u0435\u0435\u0442 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u043a\u043e\u0441\u044f\u043a\u0438 \u0432 \u043a\u043e\u0434\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u0442\u044c \u0441\u043c\u044b\u0441\u043b \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443. \u0412 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 DI \u0432\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0443\u0441\u043b\u043e\u0432\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u0434\u0432\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u2013 \u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0438\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438 \u0438 \u0431\u0438\u043d\u0430\u043c\u0438. \u041f\u0435\u0440\u0432\u044b\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0432 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0435 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u044b \u043a \u043d\u0435\u043c\u0443. \u0412\u0442\u043e\u0440\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0441\u0430\u043c\u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043c\u043e\u0433\u0443\u0442 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0431\u0438\u043d\u044b, \u043d\u043e \u043d\u0435 \u043d\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u044b. \u0418\u043d\u043e\u0433\u0434\u0430 \u0431\u044b\u0432\u0430\u044e\u0442 \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"java\">import org.jetbrains.annotations.Nullable;  public class Jedi {     private long id;     private String name;     @Nullable     private Long masterId;      \/\/ fields, constructors, getters\/setters, equals, hashCode, toString, etc...      public long getId() {         return id;     }      public String getName() {         return name;     }      @Nullable     public Long getMasterId() {         return masterId;     }      @Nullable     public Jedi getMaster() {         if (masterId == null) {             return null;         }         return DBJedi.getJedi(masterId);     } } <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/7c3\/022\/91e\/7c302291e07c5db41437bbdd118e4e56.jpg\" width=\"400\"\/><\/p>\n<p>  \u041f\u043e\u0440\u044f\u0434\u043e\u0447\u043d\u044b\u0439 \u0414\u0436\u0435\u0434\u0430\u0439 \u043c\u0435\u0442\u043e\u0434 getMaster \u0443\u0431\u0435\u0440\u0435\u0442 \u0432\u043e\u043e\u0431\u0449\u0435 \u0438\u043b\u0438 \u0436\u0435 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u0442 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 (\u0441\u0435\u0440\u0432\u0438\u0441). \u0412 \u0438\u0442\u043e\u0433\u0435 \u043a\u043b\u0430\u0441\u0441 Jedi \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0438\u043d\u043e\u043c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u043d\u043e\u0441 \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u043e \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0442 \u043d\u0435\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043a\u043e\u0434, \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u0434\u043b\u044f \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430), \u043c\u043e\u0436\u043d\u043e \u0435\u0433\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c deprecated \u0438 \u043f\u043e\u043a\u0430 \u0447\u0442\u043e \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c (\u043a\u0430\u043a \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2013 \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u0430\u043b\u0435\u043d, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u044e\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 Guava).<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 DBJedi:<\/p>\n<pre><code class=\"java\">public class DBJedi {     public static Jedi getJedi(long id) {         DataSource dataSource = ConnectionPools.getDataSource(&quot;jedi&quot;);          Jedi jedi;         \/\/ magic         return jedi;     } } <\/code><\/pre>\n<p>\u041f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 singleton, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java\">import javax.sql.DataSource;  public class DBJedi {     private static final DBJedi instance = new DBJedi();      private final ConnectionPools connectionPools;      private DBJedi() {         this.connectionPools = ConnectionPools.getInstance();     }      public static DBJedi getInstance() {         return instance;     }      public Jedi getJedi(long id) {         DataSource dataSource = connectionPools.getDataSource(&quot;jedi&quot;);          Jedi jedi;         \/\/ magic         return jedi;     } } <\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0440\u043e\u0439\u043d\u0443\u044e \u0438 \u0447\u0438\u0442\u0430\u0435\u043c\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043a\u043e\u0434\u0430 (\u0432\u0435\u0441\u044c\u043c\u0430 \u0441\u043f\u043e\u0440\u043d\u044b\u0439 \u0444\u0430\u043a\u0442, \u043a\u043e\u043d\u0435\u0447\u043d\u043e). \u0415\u0441\u043b\u0438 \u0434\u043e\u0432\u0435\u0441\u0442\u0438 \u043d\u0430\u0447\u0430\u0442\u043e\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430, \u0432 \u0446\u0435\u043b\u043e\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 DI \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u0433\u0430\u0439\u0434\u0430\u043c.<br \/>  \u041d\u043e \u0435\u0441\u043b\u0438 \u0412\u044b \u2014 \u0421\u0438\u0442\u0445, \u0442\u043e \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u043a\u043b\u0430\u0441\u0441\u044b (\u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u2013 \u043a\u043b\u0430\u0441\u0441 Jedi \u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u043c getMaster), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e-\u0445\u043e\u0440\u043e\u0448\u0435\u043c\u0443 \u043d\u0435 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u0435\u0449\u0435 \u0440\u0430\u0437 \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c \u043e \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u043d\u0438\u044f DI. \u0415\u0441\u043b\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u0432\u0441\u0435 \u0436\u0435 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u2014 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c.<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0430 Guice, \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043f\u0440\u043e\u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043d\u0430 Spring. \u041d\u0430\u0441\u0447\u0435\u0442 \u0432\u044b\u0431\u043e\u0440\u0430 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u2014 \u0432\u044b\u0431\u0438\u0440\u0430\u0439\u0442\u0435 \u0442\u043e\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043b\u0443\u0447\u0448\u0435 \u0437\u043d\u0430\u0435\u0442\u0435 <s>\u0438 \u043d\u0435\u0432\u0430\u0436\u043d\u043e \u043a\u0430\u043a\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430 \u043b\u0438\u0441\u0442\u043e\u0447\u0435\u043a \u043d\u0430 \u0435\u0433\u043e \u043b\u043e\u0433\u043e<\/s>.<\/p>\n<h5>\u041f\u043b\u043e\u0445\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 1 \u2013 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 Injector<\/h5>\n<p><img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/852\/79b\/b22\/85279bb22379eb75607eefdcf9034c42.jpg\" width=\"400\"\/><br \/>  \u0412 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0441\u0442\u0430\u043d\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u2013 \u0433\u0434\u0435 \u0432\u0437\u044f\u0442\u044c \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u0438\u043d\u0436\u0435\u043a\u0442\u043e\u0440\u0430, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u044b? \u0417\u0430\u0432\u0435\u0434\u0435\u043c \u0443\u0442\u0438\u043b\u0438\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441:<\/p>\n<pre><code class=\"java\">import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.TestOnly; import com.google.inject.Injector; \/\/ import com.google.common.base.Preconditions; \/\/ guava  public class InjectorUtil {     private static volatile Injector injector;      public static void setInjector(@NotNull Injector injector) {         \/\/ Preconditions.checkNotNull(injector);         \/\/ Preconditions.checkState(InjectorUtil.injector == null, &quot;Injector already initialized&quot;);         InjectorUtil.injector = injector;     }      @TestOnly     public static void rewriteInjector(@NotNull Injector injector) {         \/\/ Preconditions.checkNotNull(injector);         InjectorUtil.injector = injector;     }      @Deprecated \/\/ use fair injection, Sith!     @NotNull     public static Injector getInjector() {         \/\/ Preconditions.checkState(InjectorUtil.injector != null, &quot;Injector not initialized&quot;);         return InjectorUtil.injector;     } } <\/code><\/pre>\n<p>\u0414\u043b\u044f Spring \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u043e Injector \u2014 ApplicationContext. \u041b\u0438\u0431\u043e \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0432\u0430\u0440\u0438\u0430\u043d\u0442:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0448\u043c\u0430\u0440\u043d\u044b\u0439 \u0441\u043e\u043d \u043f\u0435\u0440\u0444\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0441\u0442\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware;  import javax.inject.Named;  @Named public class ApplicationContextUtil implements ApplicationContextAware { \tprivate static volatile ApplicationContext applicationContext;  \tpublic void setApplicationContext(ApplicationContext applicationContext) { \t\tApplicationContextUtil.applicationContext = applicationContext; \t}  \t@Deprecated \tpublic static ApplicationContext getApplicationContext() { \t\t\/\/ Preconditions.checkState(applicationContext != null); \t\treturn applicationContext; \t} } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448\u0438 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java\">@javax.inject.Singleton @javax.inject.Named \/\/ \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u043b\u044f Spring component-scan, \u0432 Guice \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f public class DBJedi {     private final ConnectionPools connectionPools;      @javax.inject.Inject     public DBJedi(ConnectionPools connectionPools) {         this.connectionPools = connectionPools;     }      @Deprecated     public static DBJedi getInstance() {         return InjectorUtil.getInjector().getInstance(DBJedi.class);     }      public Jedi getJedi(long id) {         DataSource dataSource = connectionPools.getDataSource(&quot;jedi&quot;);          Jedi jedi;         \/\/ ...         return jedi;     } } <\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0449\u0430\u044e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 JSR-330, \u043f\u0430\u043a\u0435\u0442 javax.inject. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0438\u0445, \u043c\u043e\u0436\u043d\u043e \u0432\u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u0441 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0441 \u043e\u0434\u043d\u043e\u0433\u043e DI \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439, \u0432 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u0432\u043e\u043e\u0431\u0449\u0435 \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 (\u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 JSR-330-\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438). \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f Named \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c bean \u0432 spring-context.xml, \u0435\u0441\u043b\u0438 \u0432 xml-\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c, \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u0431\u0440\u0430\u0442\u044c.<\/p>\n<h5>\u041f\u043b\u043e\u0445\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 2 \u2013 Bean Factory<\/h5>\n<p><img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/e66\/ae0\/81a\/e66ae081a4f07a371ad4fe682475ea63.jpg\" width=\"400\"\/><br \/>  \u0415\u0441\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0438\u043d\u043e\u043c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a singleton-\u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441-\u0444\u0430\u0431\u0440\u0438\u043a\u0443:<\/p>\n<pre><code class=\"java\">public class Jedi {     private long id;     private String name;     @Nullable     private Long masterId;      private final DBJedi dbJedi;      private Jedi(long id, String name, @Nullable masterId, DBJedi dbJedi) {         this.id = id;         this.name = name;         this.masterId = masterId;          this.dbJedi = dbJedi;     }      \/\/...      public long getId() {         return id;     }      public String getName() {         return name;     }      @Nullable     public Long getMasterId() {         return masterId;     }      @Nullable     public Jedi getMaster() {         if (masterId == null) {             return null;         }         return dbJedi.getJedi(masterId);     }      @Singleton     @Named     public static class Factory {         private final DBJedi dbJedi;          @Inject         public Factory(DBJedi dbJedi) {             this.dbJedi = dbJedi;         }          @Deprecated \/\/ refactor Jedi class to simple bean, Sith!         public Jedi create(long id, String name, @Nullable masterId) {                 return new Jedi(id, name, masterId, dbJedi);         }     } } <\/code><\/pre>\n<p>  <\/p>\n<h5>\u041f\u043b\u043e\u0445\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 3 \u2014 \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/h5>\n<p><img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/fe8\/ba8\/b2d\/fe8ba8b2d98746e5c5bbc53874a0a469.jpg\" width=\"400\"\/><br \/>  \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438 DBJedi \u0438 Jedi.Factory \u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c. \u041f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 runtime \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 DI-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, StackOverflowError. \u0422\u0443\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 Provider:<\/p>\n<pre><code class=\"java\">import javax.inject.Singleton; import javax.inject.Named; import javax.inject.Inject; import javax.inject.Provider; import javax.sql.DataSource;  @Singleton @Named public class DBJedi {     private final ConnectionPools connectionPools;     private final Provider&lt;Jedi.Factory&gt; jediFactoryProvider;      @Inject     public DBJedi(ConnectionPools connectionPools, Provider&lt;Jedi.Factory&gt; jediFactoryProvider) {         this.connectionPools = connectionPools;         this.jediFactoryProvider = jediFactoryProvider;     }      @Deprecated     public static DBJedi getInstance() {         return InjectorUtil.getInjector().getInstance(DBJedi.class);     }      public Jedi getJedi(long id) {         DataSource dataSource = connectionPools.getDataSource(&quot;jedi&quot;);          \/\/ ...          final Jedi.Factory jediFactory = jediFactoryProvider.get();         return jediFactory.create(id, name, masterId);     } } <\/code><\/pre>\n<p>\u0412\u0435\u0440\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e generic-\u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c Reflection. \u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f Guice \u0438 Spring, \u043e\u043d\u0438 \u043e\u0431\u0430 \u0447\u0438\u0442\u0430\u044e\u0442 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 generic-\u0442\u0438\u043f.<\/p>\n<h5>\u041f\u0438\u0448\u0435\u043c \u0442\u0435\u0441\u0442\u044b<\/h5>\n<p><img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/aa6\/7d0\/70b\/aa67d070bab94749774a9e208a10ca4a.jpg\" width=\"400\"\/><br \/>  \u0412 testng \u0435\u0441\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f Guice, \u0443\u043f\u0440\u043e\u0449\u0430\u044e\u0449\u0430\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430. \u0414\u043b\u044f Spring \u2014 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442 org.springframework:spring-test.<br \/>  \u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0435\u0441\u0442 \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432:<\/p>\n<pre><code class=\"java\">import org.testng.annotations.*; import com.google.inject.Injector; import com.google.inject.AbstractModule;  @Guice(modules = JediTest.JediTestModule.class) public class JediTest {     private static final long JEDI_QUI_GON_ID = 12;     private static final long JEDI_OBI_WAN_KENOBI_ID = 22;      @Inject     private Injector injector;      @Inject     private DBJedi dbJedi;      @BeforeClass     public void setInjector() {         InjectorUtil.rewriteInjector(injector);     }      @Test     public void testJedi() {         final Jedi obiWan = dbJedi.getJedi(JEDI_OBI_WAN_KENOBI_ID);         final Jedi master = obiWan.getMaster();         Assert.assertEquals(master.getId(), JEDI_QUI_GON_ID);     }      public static class JediTestModule extends AbstractModule {         @Override         public void configure() {             \/\/ \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f ConnectionPools \u043e\u043f\u0443\u0449\u0435\u043d\u0430, \u0442.\u043a. \u044d\u0442\u0443 \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e             bind(ConnectionPools.class).toInstance(new ConnectionPools(&quot;pools.properties&quot;));         }     } } <\/code><\/pre>\n<p>  <\/p>\n<h5>\u0410 \u043f\u043e\u0442\u043e\u043c-\u0442\u043e \u0447\u0442\u043e?<\/h5>\n<p>\u0410 \u043f\u043e\u0442\u043e\u043c \u0443 \u043d\u0430\u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u0434\u0432\u0430 \u0438\u0441\u0445\u043e\u0434\u0430. \u041f\u0435\u0440\u0432\u044b\u0439 \u2014 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442\u043e\u043c. \u0422\u0430\u043a \u0441\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043c\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432, \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u043d\u0430 \u0447\u0435\u0441\u0442\u043d\u044b\u0439 DI \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c, \u0432 \u043d\u0435\u043c \u0431\u044b\u043b\u043e \u043c\u043d\u043e\u0433\u043e legacy-\u043a\u043e\u0434\u0430. \u0414\u0443\u043c\u0430\u044e, \u044d\u0442\u0430 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0437\u043d\u0430\u043a\u043e\u043c\u0430 \u043c\u043d\u043e\u0433\u0438\u043c. \u041c\u043e\u0436\u043d\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0435\u0435 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u043c\u0435\u043d\u0438\u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u043b\u0435 \u0432 InjectorUtil \u043d\u0430 ThreadLocal, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0440\u0435\u0448\u0438\u0432 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 concurrent-\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441 \u0440\u0430\u0437\u043d\u044b\u043c DI-\u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435\u043c \u0432 \u043e\u0434\u043d\u043e\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">public class InjectorUtil {     private static final ThreadLocal&lt;Injector&gt; threadLocalInjector =             new InheritableThreadLocal&lt;Injector&gt;();      private InjectorUtil() {     }      \/**      * Get thread local injector for current thread      *      * @return      * @throws IllegalStateException if not set      *\/     @NotNull     public static Injector getInjector() throws IllegalStateException {         final Injector Injector = threadLocalInjector.get();         if (Injector == null) {             throw new IllegalStateException(&quot;Injector not set for current thread&quot;);         }         return Injector;     }      \/**      * Set Injector for current thread      *      * @param Injector      * @throws java.lang.IllegalStateException if already set      *\/     public static void setInjector(@NotNull Injector injector) throws IllegalStateException {         if (injector == null) {             throw new NullPointerException();         }         if (threadLocalInjector.get() != null) {             throw new IllegalStateException(&quot;Injector already set for current thread&quot;);         }         threadLocalInjector.set(injector);     }      \/**      * Rewrite Injector for current thread, even if already set      *      * @param injector      * @return previous value if was set      *\/     public static Injector rewriteInjector(@NotNull Injector injector) {         if (injector == null) {             throw new NullPointerException();         }         final Injector prevInjector = threadLocalInjector.get();         threadLocalInjector.set(injector);         return prevInjector;     }      \/**      * Remove Injector from thread local      *      * @return Injector if was set, else null      *\/     public static Injector removeInjector() {         final Injector prevInjector = threadLocalInjector.get();         threadLocalInjector.remove();         return prevInjector;     } } <\/code><\/pre>\n<\/div>\n<\/div>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u2014 \u0434\u043e\u0432\u0435\u0441\u0442\u0438 \u0434\u0435\u043b\u043e \u0434\u043e \u043a\u043e\u043d\u0446\u0430. \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0437\u0431\u0430\u0432\u0438\u043c\u0441\u044f \u043e\u0442 \u043c\u0435\u0442\u043e\u0434\u0430 Jedi.getMaster, \u0442\u043e\u0433\u0434\u0430 Jedi \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 bean. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 Jedi.Factory. \u0418\u0441\u0447\u0435\u0437\u043d\u0435\u0442 \u0438 \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043d\u0435 \u0441\u0442\u0430\u043d\u0435\u0442 \u0438 \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 InjectorUtil. \u041f\u0440\u043e\u0435\u043a\u0442\u044b \u0431\u0435\u0437 \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u2014 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u043e\u0439\u0442\u0438 \u0432\u0441\u0435 \u044d\u0442\u0438 \u044d\u0442\u0430\u043f\u044b, \u0447\u0442\u043e\u0431\u044b \u043b\u0443\u0447\u0448\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 DI \u0438 \u043f\u0440\u043e\u0447\u0443\u0432\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u0438 \u043d\u044e\u0430\u043d\u0441\u044b \u043d\u0430 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435. <s>\u0410 \u0442\u043e\u0442, \u043a\u0442\u043e \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c \u043d\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u0441\u044f, \u043f\u0443\u0441\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0431\u0440\u043e\u0441\u0438\u0442 \u0432 \u043c\u0435\u043d\u044f \u043f\u0435\u0447\u0435\u043d\u044c\u043a\u043e\u0439.<\/s><\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/ed6\/f4b\/644\/ed6f4b6449c2d732bb9b39d16fc0ba87.jpg\" width=\"400\"\/><\/p>\n<p>  \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0438 \u044d\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0432\u0441\u0435. \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u0435 \u043d\u0430 DI \u2014 \u043e\u0431\u0449\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u0435\u0441\u0442\u044c \u0441\u043c\u044b\u0441\u043b \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u043e\u0442 \u0441\u0430\u043c\u043e\u0433\u043e DI, \u043e\u0431 \u044d\u0442\u043e\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0410\u0445, \u0434\u0430, \u0447\u0443\u0442\u044c \u043d\u0435 \u0437\u0430\u0431\u044b\u043b<\/b><\/p>\n<div class=\"spoiler_text\"><img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/be1\/e5f\/13e\/be1e5f13efb8d336306506c478766048.jpg\" width=\"400\"\/><\/div>\n<\/div>\n<p>  <i>May the &#8212;force be with you.<\/i>    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/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=\"http:\/\/habrahabr.ru\/post\/217523\/\"> http:\/\/habrahabr.ru\/post\/217523\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0412\u043d\u0435\u0441\u0443 \u0438 \u0441\u0432\u043e\u0439 \u0432\u043a\u043b\u0430\u0434 \u0432 \u0442\u0440\u0435\u043d\u0434 <a href=\"http:\/\/habrahabr.ru\/post\/192320\/\">\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/a>.<br \/>  \u041c\u043d\u043e\u0433\u0438\u043c \u0438\u0437 \u0432\u0430\u0441 \u0437\u043d\u0430\u043a\u043e\u043c\u0430 \u0434\u0438\u043b\u0435\u043c\u043c\u0430: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u0438 DI \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0438\u043b\u0438 \u043d\u0435\u0442.<br \/>  \u041f\u043e\u0432\u043e\u0434\u044b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043d\u0430 DI:<\/p>\n<ul>\n<li>\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0430\u0432\u0442\u043e-\u0442\u0435\u0441\u0442\u043e\u0432<\/li>\n<li>\u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445<\/li>\n<li>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 3rd-party \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u043d\u0430 DI<\/li>\n<li>\u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 DI<\/li>\n<\/ul>\n<p>\u0414\u043e\u0432\u043e\u0434\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c DI:<\/p>\n<ul>\n<li>\u0443\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 (\u043f\u043e\u043d\u0430\u0447\u0430\u043b\u0443)<\/li>\n<li>\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/li>\n<li>\u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 DI<\/li>\n<\/ul>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442, \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0430 DI. \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0447\u0443\u0432\u0441\u0442\u0432\u0443\u044e\u0442 \u0441\u0432\u043e\u0439 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b, \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043c\u0438\u0434\u0438\u0445\u043b\u043e\u0440\u0438\u0430\u043d \u0432 \u043a\u0440\u043e\u0432\u0438 \u0437\u0430\u0448\u043a\u0430\u043b\u0438\u0432\u0430\u0435\u0442.<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/cc6\/bdc\/711\/cc6bdc711f607edb74b597118a6794f9.jpg\" width=\"400\"\/><br \/>  <i>\u041f\u0443\u0442\u044c \u0442\u0435\u0431\u044f \u0436\u0434\u0435\u0442 \u0442\u0435\u0440\u043d\u0438\u0441\u0442\u044b\u0439 \u0438 \u0434\u043e\u043b\u0433\u0438\u0439, \u043c\u043e\u0439 \u044e\u043d\u044b\u0439 \u043f\u0430\u0434\u0430\u0432\u0430\u043d.<\/i><\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0438 \u0432 \u043d\u0435\u043c \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u043e\u0434\u043d\u0438\u043c \u043a\u043e\u043c\u043c\u0438\u0442\u043e\u043c \u0432\u0440\u044f\u0434 \u043b\u0438 \u0443\u0434\u0430\u0441\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043b\u043e\u0445\u0438\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u043a, \u0430 \u043f\u043e\u0442\u043e\u043c&#8230;  <\/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-217523","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/217523","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=217523"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/217523\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=217523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=217523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=217523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}