Closed dpeek closed 9 years ago
The important changes are in Injector. Basically:
mapValue
/mapValueForTypeId
, mapClass
/mapClassForTypeId
mapValue
no longer has a magic case for strings, you just call mapValueForTypeId
with the ID of your typegetRuleForTypeId
creates rule on injector if needed and returns itfindRuleForTypeId
looks for rule with result and traverses ancestors if neededunmap
now removes rule instead of setting null resultThe rest is just project cleanup and using our new build tool for some stuff.
I'm open to feedback on the API renaming – ...ForTypeId
makes for some long method names but I wanted to be clear what the difference was with the macro versions.
Another idea I has was Injector.useValue(value)
which would basically be like mapValue
but it gets the type from the value itself (kind of like mapSingleton
for other types I guess)
Ah hah. One or two more changes :)
Hard to argue that the changes aren't for the better, though.
That does look more readable... I'll try look at it tomorrow. I've got several projects with fairly complex DI, though they are each similar use cases. Hopefully it'll be a sufficient test though...
I basically took a look at swift suspenders v2 and got inspired. I'm just trying to figure out how to bring some stricter typing into the equation, but the primitive/class thing is making it tricky.
I'm also thinking of making map
work with type identifiers so that mapType
isn't needed publicly. For the map value use case we could add another specific method which detects the type of the value.
@jasononeil OK, so hopefully the last round of big changes, mostly internal APIs but also some that might affect you. Some testing would be much appreciated, hopefully I can still get v2 out before Saturday!