Sha256: 7ebee5cdc6f9ae2c5153306a0577d8e1a0421b7300d0e0b466f54ed28cc6a5c6

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

The service locator works well when there are few dependencies, and the dependency graph is not very deep. However, it has a few drawbacks:

# It requires each object to accept the locator as a parameter, and to know how to use it. This is problematic if you want to use existing classes that were created without knowledge of a locator. (I.e., @Logger@, in the Ruby library).

# It requires each object to know what the services are named, in the locator. If you ever decide to change the name of a service in the locator, you may have to change lots of code to comply with the change.

# For deep dependency graphs, it can become cumbersome to have to pass the locator to each constructor.

This is where _dependency injection_ comes in. It allows you to define how each service is initialized, including setting dependencies (either via constructor parameters or via property accessors). In fact, it can do a lot more than that, even allowing you to specify how the lifecycle of the service should be managed and hooking "interceptors" onto the service to filter method invocations.

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
needle-0.9.0 doc/manual/parts/04_overview.txt
needle-1.1.0 doc/manual/parts/04_overview.txt
needle-1.2.0 doc/manual/parts/04_overview.txt
needle-1.0.0 doc/manual/parts/04_overview.txt