{"id":1879,"date":"2016-10-11T10:29:55","date_gmt":"2016-10-11T10:29:55","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=1879"},"modified":"2016-10-11T11:04:02","modified_gmt":"2016-10-11T11:04:02","slug":"inversion-of-control-vs-dependency-injection","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/inversion-of-control-vs-dependency-injection\/","title":{"rendered":"Inversion of Control vs Dependency Injection"},"content":{"rendered":"<p>IoC is a generic term meaning rather than having the application call the methods in a framework, the framework calls implementations provided by the application.Inversion of Control (IoC) means any sort of programming style where an overall <strong>framework or run-time controlled the program flow<\/strong>.<\/p>\n<p><strong>Dependency Injection is a Type of IoC<\/strong><\/p>\n<p>IoC means that <strong>objects do not create other objects<\/strong> on which they rely to do their work. Instead, they <strong>get the objects that they need from an outside service (for example, xml file or single app service)<\/strong>.<\/p>\n<p>DI means the IoC principle of getting <strong>dependent object is done without using concrete objects but abstractions (interfaces)<\/strong>. This makes all components chain testable, cause higher level component doesn&#8217;t depend on lower level component, only from interface. <\/p>\n<p><strong>Techniques to implement inversion of control<\/strong><\/p>\n<ol>\n<li>using a factory pattern<\/li>\n<li>using a service locator pattern<\/li>\n<li>using a dependency injection of any given below type:<\/li>\n<ol>\n<li>a constructor injection<\/li>\n<li>a setter injection<\/li>\n<li>an interface injection<\/li>\n<\/ol>\n<\/ol>\n<p>DI is a form of IoC, where implementations are passed into an object through constructors\/setters\/service look-ups, which the object will &#8216;depend&#8217; on in order to behave correctly.<\/p>\n<p><strong>IoC without using DI<\/strong>, for example would be the <strong>Template pattern<\/strong> because the implementation can only be changed through sub-classing.<\/p>\n<p>DI Frameworks are designed to make use of DI and can define interfaces (or Annotations in Java) to make it easy to pass in implementations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>IoC is a generic term meaning rather than having the application call the methods in a framework, the framework calls implementations provided by the application.Inversion of Control (IoC) means any sort of programming style where an overall framework or run-time controlled the program flow. Dependency Injection is a Type of IoC IoC means that objects&hellip; <a href=\"https:\/\/codethataint.com\/blog\/inversion-of-control-vs-dependency-injection\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[192,211],"tags":[],"class_list":["post-1879","post","type-post","status-publish","format-standard","hentry","category-interview","category-theory"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1879","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=1879"}],"version-history":[{"count":1,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1879\/revisions"}],"predecessor-version":[{"id":1880,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1879\/revisions\/1880"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=1879"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=1879"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=1879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}