bkeepers/morphine — Issue #1: How is it better than old-fashioned method definition?
Author: mislav
Created: 2012-03-07 15:49:14+00:00
State: open

How is morphine better than just defining a method with memoization?

~~~ rb
register :track_service do
KestrelTrackService.new(kestrel_client, config.tracking_queue)
end

## vs.

def track_service
@track_service ||= KestrelTrackService.new(kestrel_client, config.tracking_queue)
end
~~~

I fail to see how morphine is a lightweight library for dealing with dependency injection. I only see it as a simple DSL that wraps the memoization pattern. Does morphine allow me to swap out `track_service` with another kind of object in certain scenarios (in another environment, or at runtime)? It doesn't seem like it.