tschneidereit / SwiftSuspenders

NOTE: Find the offical repo at http://github.com/robotlegs/swiftsuspenders
https://github.com/robotlegs/swiftsuspenders
MIT License
280 stars 89 forks source link

Named injections, map.toValue(null), satisfies() and getInstance() #62

Closed darscan closed 12 years ago

darscan commented 12 years ago

If I map a named value to null, satisfies returns true, but getInstance fails:

injector.map(Function, 'callback').toValue(null);
if (injector.satisfies(Function, 'callback'))
  injector.getInstance(Function, 'callback');

Error: No mapping found for request Function|callback. getInstance only creates an unmapped instance if no name is given.

tschneidereit commented 12 years ago

Interesting. In Swiftsuspenders 1, I had the core assumption that null wasn't a valid value to map. Meaning that mapping null was pretty much the same as not doing a mapping. It seems like in 2 I inadvertently watered down that assumption.

Unfortunately, it's not that easy to restore it without quite some added complexity. Because of that (and because I prefer early errors) the best course of action seems to be to simply throw on an attempt to map null.

Yell if that seems to harsh, otherwise I'll just go ahead with it.

darscan commented 12 years ago

Yell! I think that null is a perfectly valid value to map, what was your core assumption based on?

tschneidereit commented 12 years ago

So there was an elaborate theory behind this that was based on principles of simplicity and I'm pretty sure that Occam's Razor figured into it and it was Very Important in its entirety.

Unfortunately, I can't remember the least bit of it and it might have been a fever dream after all. Maybe not even that is true, who knows? Anyway: yell accepted.

darscan commented 12 years ago

hahaa!!! Speaking of simplicity, Occam's Razor and The Principle Of Least Surprise, I would expect that what I map is what I get. Symmetry is important, especially for libraries upon which other libraries are built :)

tschneidereit commented 12 years ago

Right. Maybe it was that and I surprised myself by doing the opposite? We will never know, I'm afraid. We will have support for mapping 'null' as a value again, though.

darscan commented 12 years ago

LOL and YAY!