Talk:Dependency injection

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Computing / Software (Rated Start-class, Mid-importance)
WikiProject icon This article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
Start-Class article Start  This article has been rated as Start-Class on the project's quality scale.
 Mid  This article has been rated as Mid-importance on the project's importance scale.
Taskforce icon
This article is supported by WikiProject Software (marked as Mid-importance).
 

Links[edit]

Framework based DI Code Example[edit]

I highly discourage anybody from using hard coded strings in-line. The example in the last section of the page would be better if we added an static class to it that contains the strings:

//static class provided by the framework or written by the user to indicate which dependencies are available
public static class MyAvailableServices{
    public static final string CarBuilderService = "CarBuilderService";
    public static final string VanBuilderService = "VanBuilderService";
}

public class MyApplication {
    public static void main(String[] args) {
        Service service = (Service)DependencyManager.get(MyAvailableServices.CarBuilderService);
        Car car = (Car)service.getService(Car.class);
        car.setPedalPressure(5);
        float speed = car.getSpeedInMPH();
    }
}

Registry Pattern[edit]

Should not this article reference the Registry Pattern which was very prevalent until IoC/DI was popularised?

References[edit]

Dumb it down[edit]

I came here after hearing about DI for the first time today. I understand all the principles involved, but the intro depends on so many buzzwords that I'm still in the dark. I finally found a Stack Overflow article that puts it much more clearly... rather than your class creating instances of other classes, DI "makes that someone else's problem."

If I understand correctly, DI basically means: rather than using "new" to create a child object in your class, outside code creates the child object for you, then passes it in through the constructor or through a mutator, a set method or a Property assignment.

Is this correct? If so, can we incorporate something like this into the opening section? -- TomXP411[Talk] 00:09, 25 August 2016 (UTC)