Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Note on Dependency Injection #6

Open
sagikazarmark opened this issue Feb 25, 2018 · 1 comment
Open

Note on Dependency Injection #6

sagikazarmark opened this issue Feb 25, 2018 · 1 comment

Comments

@sagikazarmark
Copy link

sagikazarmark commented Feb 25, 2018

Thanks for this example, it's really great.

I would like to comment one thing though, namely the section about Dependency Injection.

You state that dependency injection is not always necessary, you even say one doesn't need it and say something about runtime performance costs.

The fact is though, that there are examples of dependency injection in this project as well, like the one here.

Dependency injection is almost always necessary to adhere the Dependency Inversion Principle which is one of the key pillars of Clean Architecture. It's the moment when you pass a set of dependencies from the outside to your object instead of creating them inside (thus avoiding hard coupling between them).

It is true that you can do dependency injection manually, but at certain level it can become cumbersome.

I believe you meant to say dependency injection containers (which would make perfect sense for most of this section).

I would also argue with the runtime performance hit point. Clearly dependency injection frameworks/containers always use some sort of hacky way to make DI user friendly, but that cost is usually paid at the very beginning of the application initialization and does not affect the runtime performance.

(I have to admit that I haven't worked much with Java or .NET, so I'm not familiar with their DIC solutions, but I'm pretty sure the situation is still much better than in case of script languages where initialization happens for each request and to make things faster production builds "compile" the container to avoid rebuilding the dependency tree for every request)

@CaptainCodeman
Copy link
Owner

Yeah, it was more for the Java / .NET crowd where it sometimes feels like half the development effort is configuring dependecy injection (containers) when, if you take a step back, they don't give you that much extra over a much simpler approach (manual factory approach)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants