RFC: Dependency Injection For Object/StaticObject #620

Closed
rmarscher opened this Issue Aug 28, 2012 · 7 comments

Comments

Projects
None yet
4 participants
Contributor

rmarscher commented Aug 28, 2012

Hi everyone,

This is an RFC idea. Somehow I had in my head that Lithium had this via these base classes, but now I realize it's only custom implemented in a few classes.

Wouldn't it be nice for the core object classes to have a way to update the defaults that are configured when __construct/_init is run? You could inject different defaults for things in $_config and those that are configured via the $_autoConfig?

This specifically came up in a project where we wanted to override the $_classes array and realized we had to subclass to do so.

The lithium\net\http\Router has a config() method that does it for classes and unicode settings. It think it would be awesome if it was a feature of the core Object and StaticObject classes.

Owner

nateabele commented Aug 29, 2012

I'd have to see an example, but Lithium does support this. You can pass a 'classes' array to an instance, which will be merged with the list of existing dependencies.

Member

mackstar commented Sep 22, 2012

@nateabele Don't you mean when you create an instance? You can't do this when it is already instantiated can you?

Contributor

rmarscher commented Sep 22, 2012

I've been meaning to add more detail to this, but haven't had a chance to write up some gists. But yeah, you can't do it after instantiation. My use case is more for classes that you are not directly instantiating - like a Controller. The solution would be something like what Router::config() does. Or maybe making the __init methods called by Libraries::load() filterable.

Owner

nateabele commented Sep 22, 2012

You can filter Libraries::instance(), which is responsible for almost all object instantiation. Anything static should have a manipulable config() method.

Contributor

rmarscher commented Sep 22, 2012

Ah, great. That might solve this. I'll check it out and most likely close this ticket.

Contributor

jails commented Dec 14, 2012

Still an issue ?

Contributor

rmarscher commented Dec 15, 2012

I'm closing. Thanks!

rmarscher closed this Dec 15, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment