Jump to content

Talk:Dependency injection

Page contents not supported in other languages.
Add topic
From Wikipedia, the free encyclopedia
Latest comment: 21 days ago by ~2026-41682-07 in topic Revolut Bank

[edit]

Registry Pattern

[edit]

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

Needlessly Object Oriented

[edit]

Isn't the description needlessly presuming an object oriented approach? Dependency injection is just as easily performed in a classes programming language. It's the basis of how C's std library qsort operates:

   int cmpfunc (const void * a, const void * b) {
     return ( someMathWithAandB);
   }
   qsort(array, size, sizeof(int), cmpfunc);

 Preceding unsigned comment added by 97.122.84.35 (talk) 06:55, 28 November 2020 (UTC)Reply

Classes programming is usually OO too. Also a program could be designed with OO principles but implemented with an non-OO language. eg:
#include <iostream>
#include <algorithm>
#include <vector>

using array_t = std::vector<int>;

struct data {
	array_t array;
};
struct fns {
	int (*cmpfunc) (const void * a, const void * b) = 0;
};

int cmpint(const void * a, const void * b){
	int i {*reinterpret_cast<int const *>(a)};
	int j {*reinterpret_cast<int const *>(b)};
	return  i-j;
}

void qsort(data& data, fns const& f){
	std::sort(std::begin(data.array), std::end(data.array), [f](auto a, auto b){
		return f.cmpfunc(&a, &b) < 0;
	});
}

int main() {
	data data;
	data.array = array_t {4, 6, 2};
	fns fns;
	fns.cmpfunc = cmpint;
	
	qsort(data, fns);

	for(int i: data.array){
		std::cout << i << '\n';
	}
}

194.207.86.26 (talk) 08:57, 22 December 2021 (UTC)Reply

Dependency Injection is a fancy term for reference passing from the OOP world. The term Dependency Injection simply doesn't get much usage outside of OOP. Likely because the functional world already knows how to use composition.

Galhalee (talk) 04:00, 20 August 2022 (UTC)Reply

It's not OOP; I've never heard of "injection" from within the OOP discipline, and I've been working with C++, Java, UML and design patterns for a long time. It is only since I've been working with server-side Java "Servlet" systems and browser-side Javascript AngularJS coding that I have heard of "injection". It's a bunch of hype intended to sound esoteric. I agree with earlier comment that it is nothing more/less than reference passing during startup. "Injection" is a silly term for this, especially since it is only a startup function. The word "injection" sounds like it should be something that could happen asynchronously, more than once, preemptively.

Revolut Bank

[edit]

https://revolut.me/r/33bd8upW1j@bartosz skalny@Revolut ~2026-41682-07 (talk) 17:02, 26 July 2026 (UTC)Reply