Skip to content

Note on Dependency Injection #6

@sagikazarmark

Description

@sagikazarmark

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions