Skip to content

Explain differences between the service container concept vs service locator (anti)pattern vs (usually property-based) dependency injection #4

@mrts

Description

@mrts

Point: service container is an IoC mechanism that can be used well or not well.

Mark Seemann:

A DI container encapsulated in a Composition Root is not a Service Locator - it's an infrastructure component.

It becomes a Service Locator if used incorrectly: when application code (as opposed to infrastructure code) actively queries a service in order to be provided with required dependencies, then it has become a Service Locator.

When a container is used according to the Register Resolve Release pattern from within a Composition Root it's all good.

References:

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