Tag Info

New answers tagged

2

Most dependency injection containers can be configured to create the dependencies as well as inject them. No need to have a separate process to create dependencies. Here is a simple example using the PHP Pimple container(http://pimple.sensiolabs.org/) // This is the importer service definition $dic['arbiter_schedule_importer_games_with_slots_xml'] = ...


2

You pretty much hit the nail on the head. Dependency injection is a great choice when you want to get dependencies that are known and unchanging at runtime or compile-time, depending on how you configure. Let's assume that you have a mailer in your application implemented by IMailer and you can use a TextBasedMailer or HtmlBasedMailer. You either build the ...


0

Do both If you are making a framework, flexibility is key. Most frameworks provide interfaces and default implementations along with empty constructors wired to defaults, but allow for you to overwrite behavior by passing in your own implementations, or passing in a framework-provided alternative implementation. public interface IReader { string Read(); } ...


0

First off, yes. Using an IoC that way is an anti-pattern. You've got a global variable in disguise there. It is natural for dependencies to "bubble up" toward the entry point of the program and constructors grow in size. That's just the nature of the beast. However let's step back and ask ourselves a question. Why do we want DI to begin with? We want ...


2

The problem is that you are using 'Dim c As New C', instead of registering C in the IoC container and requesting it from there. The dependency C requests in DoSomething should be passed in the constructor, which IoC wires for you. What makes it a bit hard is the fact that your IoC container seems to be a Singleton and is therefore accessible from everywhere. ...



Top 50 recent answers are included