atomicobject / objection

A lightweight dependency injection framework for Objective-C
http://www.objection-framework.org
MIT License
1.85k stars 223 forks source link

Inititializer dependencies support #22

Closed driis closed 12 years ago

driis commented 12 years ago

This pull requests adds support for initializers to be truly dependent on types registered with Objection. Currently, when using objection_initializer, one has to know the concrete dependency either when the type is registered, or when it is resolved. It would be nice to simply register the initializer one would like to use, and let it be up to Objection to resolve it's depencies when calling getObject; this is what this pull request adds.

You can now use objection_initializer like this:

objection_initializer(initWithEngine:, [JSObjectionDependency for:[Engine class]])

The first dependency will then be resolved when calling getObject, instead of being specified when the type is registered. Of course this also works the other way around for getObjectWithArgs, using JSObjectionDependency here allows you to override a dependency with whatever is currently registered with Objection.

There are tests for this in InitializerSpecs.m. Most of the new feature is in JSObjectionUtils.m.

I think this would be a nice addition to the Objection framework, and hope you will accept it. If you should agree with the feature, but disagree with the style or way it is implemented, please tell me and I will try to improve ;-)

jdewind commented 12 years ago

Dennis,

That is a clever way of supporting injections dependencies through an initializer that bootstraps an existing feature. Generally, I like the pull request and I'm inclined to merge it.

I'm going to go through a couple code segments and suggest some small stylistic changes before I merge it however.

Stay tuned.

jdewind commented 12 years ago

Dennis,

Thanks for the updates. I'll pull your changes in via a branch at some point this week. After some thought I'd like to perform a refactor of how dependencies, in general, are injected. It seems to me we have a number of different strategies or approaches to injection now. I'd like to abstract those strategies into their own classes instead of tacking them on in the JSObjectionInjectorEntry,

driis commented 12 years ago

Justin,

Thanks. If you need anything more from me, just ask. It will be great to have this feature included in Objection.

/Dennis

grouchal commented 12 years ago

is anything more happening with this?

driis commented 12 years ago

I would still love to have this feature included in objection, so I am hoping Justin will accept the pull request soon.

Just for the record, I would be happy to make any minor changes or refactorings needed, add any tests that you feel are missing, etc, etc.

jdewind commented 12 years ago

Sorry guys,

I'll merge this change. But I'd like to merge it into a different branch other than master. There are a few stylistic changes I'd like to make before merging it into master.

driis. Can you close this pull request and re-open it against development.

Thanks.

driis commented 12 years ago

Thanks, I've opened a pull request against development. ( #24 )