Timeline for Does SOLID Require an IoC Container (Automatic Factory)?
Current License: CC BY-SA 4.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 23, 2019 at 0:00 | vote | accept | Christian Findlay | ||
| Aug 17, 2019 at 17:44 | comment | added | Filip Milovanović | @MelbourneDeveloper: IoC Containers don't implement IoC or dependency injection, only you can do that, as DI & IoC are tools that you use purposely to control the dependency structure (coupling directions) within your own codebase, and this is in significant part based on your understanding of the project-specific problem domain. Now, if you push dependency inversion to its limit, you can still do it "manually" (look up "Pure DI"), but you may also need to manually manage object lifetime, etc. IoC containers do this for you - that's what they are for, but they are optional. | |
| Aug 17, 2019 at 9:08 | comment | added | Ben Cottrell | @MelbourneDeveloper No, dependency injection is just a plain software design pattern which prescribes a way that a class can receive its dependencies through 'injection' (e.g. from its constructors or setters). IoC containers exist outside of the classes which they control, so they aren't part of the pattern at all. Dependency injection doesn't actually describe a mechanism to provide dependencies, it only describes a code structure for a class which receives its dependencies from an unknown external source. | |
| Aug 17, 2019 at 8:49 | comment | added | Christian Findlay | Are IoC containers required for dependency injection? | |
| Aug 17, 2019 at 8:06 | comment | added | Ben Cottrell | @MelbourneDeveloper SOLID principles apply to classes (code) and not the physical objects in memory. Indeed, SOLID ensures that classes know absolutely nothing about the circumstances surrounding how their instances are created. The mechanism for allocating memory and (maybe) invoking a constructor is an irrelevant concern to be taken care of elsewhere. One of the hallmarks of SOLID principles is that a class is easily unit testable, so it is highly likely that a class created in the main application via an IOC container will be created with "new" in its unit tests. | |
| Aug 17, 2019 at 4:42 | comment | added | Christian Findlay | While I think you're right, I still don't understand how the thought experiment validates the answer. | |
| Aug 17, 2019 at 3:51 | comment | added | Robert Harvey |
Yes, the object graph is still SOLID. It doesn't matter how you create your objects. You can create them with the new keyword. You can create them with Activator.CreateInstance. You can create them via carrier pigeon. They will still be the same objects when you are done. Therefore they will still have the same SOLID characteristics.
|
|
| Aug 17, 2019 at 3:49 | comment | added | Christian Findlay | I would have thought so but judging by your wording, I'm guessing not? Care to explicate why not? | |
| Aug 17, 2019 at 3:46 | comment | added | Robert Harvey |
Thought experiment: You have three classes that meet the SOLID principles. You use the new keyword to stand up an object graph using those three classes. The object graph is still SOLID. Now you use an IoC container to stand up that same object graph instead. Is the object graph still SOLID?
|
|
| Aug 17, 2019 at 3:37 | comment | added | Christian Findlay | I like your answer but how can I validate it? | |
| Aug 17, 2019 at 3:35 | history | answered | Robert Harvey | CC BY-SA 4.0 |