tag:blogger.com,1999:blog-13487842.post9090240589652369150..comments2023-07-11T06:12:50.698-07:00Comments on Analysis 102: Depency Injection/Inversion of Control - are they the same?Michael Wileshttp://www.blogger.com/profile/06655030771595145734noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-13487842.post-8667150329639965682009-07-04T06:03:35.727-07:002009-07-04T06:03:35.727-07:00Creating the dependency outside the component and ...Creating the dependency outside the component and then providing it to the component is not a sufficient condition for achieving dependency injection. The component must necessarily also not depend on the details, otherwise the dependency cannot be injected, it has been "hard coded".<br /><br />btw, thanks for pointing out the error wrt which letter of SOLID is relevant.Michael Wileshttps://www.blogger.com/profile/06655030771595145734noreply@blogger.comtag:blogger.com,1999:blog-13487842.post-21101429994892791112009-06-27T07:05:05.303-07:002009-06-27T07:05:05.303-07:00This is probably a typo, but the Dependency Invers...This is probably a typo, but the Dependency Inversion Principle is the 'D' in SOLID and not the 'I'.<br /><br />The 'I' would be the Interface Segregation Principle.Trumpihttp://dotnet.org.za/trumpinoreply@blogger.comtag:blogger.com,1999:blog-13487842.post-18838184426282109312009-06-26T03:46:39.013-07:002009-06-26T03:46:39.013-07:00Here is another point that proves that Dependency ...Here is another point that proves that Dependency Inversion and Dependency Injection are not the same: You can inject all your dependencies, but still not achieve dependency inversion. How? By not declaring your dependencies abstract enough.<br /><br />So instead of declaring <b>public MyConstructor(AbstractDependency d)</b>, you declare <b>MyConstructor(ConcreteDependency d)</b>. You are using dependency injection, but you are not achieving dependency inversion.Trumpihttp://dotnet.org.za/trumpinoreply@blogger.comtag:blogger.com,1999:blog-13487842.post-74687779528062583692009-06-26T03:39:28.767-07:002009-06-26T03:39:28.767-07:00This comment has been removed by a blog administrator.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-13487842.post-73134342210082268832009-06-02T08:03:39.272-07:002009-06-02T08:03:39.272-07:00The goal is the segregation of arbitrary infrastru...The goal is the segregation of arbitrary infrastructural choices (such as RDBMS products, loggers, and communications middleware) from the business logic, so that these can be tested and maintained independently.<br /><br />Comparing programs which achieve this segregation with those that do not, it appears that there has been an inversion of control. That is, rather than embedding arbitrary infrastructural details within the routines that implement the business logic, a new top layer (1) builds the necessary infrastructure and (2) provides the business logic routines with access to this infrastructure. Hence, the (admittedly vague) expression _Inversion of Control_.<br /><br />Because business logic execution depends upon access to the computational infrastructure, step (2) above is called Dependency Injection.<br /><br />The expression "Dependency Injection" is specific as to the goal, but does not refer to the entire process -- as you cannot inject a dependency unless you first build it out. But it covers the most important part.<br /><br />The expression "Inversion of Control" covers the entire process, but the words are so general that it theoretically could refer to any kind of control inversion that might exist for whatever reason.<br /><br />Therefore, Dependency Injection is the better terminology.Frank Silbermannnoreply@blogger.comtag:blogger.com,1999:blog-13487842.post-57655448794838627602009-06-02T02:24:44.432-07:002009-06-02T02:24:44.432-07:00The thing is, as soon as your component uses X, e....The thing is, as soon as your component uses X, e.g. Service locator or jndi to acquire its dependencies, though you have inverted the control to some extent, the class has retained some control and I'd prefer the class to not have any control. <br /><br />To truly invert the control, i.e. for the class to have no knowledge about its dependencies (details), you necessarily have to inject them. <br /><br />I'm not sure if this is part of the inversion of control pattern but I'd prefer a system where the class is _not_ responsible for acquiring its dependencies at all. That is true inversion of control.<br /><br />Using service locator and or jndi means the class is responsible for acquiring its dependencies. Thus if you wish to change how those details are acquired you will have to change the class - effectively breaking the inversion of control.Michael Wileshttps://www.blogger.com/profile/06655030771595145734noreply@blogger.comtag:blogger.com,1999:blog-13487842.post-40655931766660524142009-06-02T01:56:09.156-07:002009-06-02T01:56:09.156-07:00A service locator is another way of doing inversio...A service locator is another way of doing inversion of control, but I do not recommend it.Giorgiohttps://www.blogger.com/profile/12689416577856305650noreply@blogger.comtag:blogger.com,1999:blog-13487842.post-60921827629211282232009-06-02T00:31:09.724-07:002009-06-02T00:31:09.724-07:00@Dusan "This can be achieved by different ways." L...@Dusan "This can be achieved by different ways." Like how?Dirkhttps://www.blogger.com/profile/08913444232450672793noreply@blogger.comtag:blogger.com,1999:blog-13487842.post-89716048913000675592009-06-01T22:38:37.511-07:002009-06-01T22:38:37.511-07:00In fact inversion of control is more general term....In fact inversion of control is more general term. Inversion of control means that you have given up creation of new instances by yourself("new" keyword). This can be achieved by different ways. One is dependency injection in which the dependencies are set to your instance by container(instance is not aware of container)... <br />Other one is "dependecy pull" this means that you are actively aware of a container and pulling the instances out of it(for example in java jndi lookup, or this kind of thing. <br /><br /><br /><br />(Sorry for my not very good english)Dusannoreply@blogger.com