Skip to content

Commit

Permalink
Merge pull request atomicobject#59 from NachoSoto/feature/awake-from-…
Browse files Browse the repository at this point in the history
…objection

Objects are also notified when dependencies are injected manually
  • Loading branch information
jdewind committed Dec 7, 2013
2 parents 6c23552 + 19b9fe6 commit b319097
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
9 changes: 1 addition & 8 deletions Source/JSObjectionInjectorEntry.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ - (void)dealloc
#pragma mark -
#pragma mark Private Methods

- (void)notifyObjectThatItIsReady:(id)object {
if([object respondsToSelector:@selector(awakeFromObjection)]) {
[object performSelector:@selector(awakeFromObjection)];
}
}

- (id)buildObject:(NSArray *)arguments {

id objectUnderConstruction = nil;
Expand All @@ -66,8 +60,7 @@ - (id)buildObject:(NSArray *)arguments {
}

JSObjectionUtils.injectDependenciesIntoProperties(self.injector, self.classEntry, objectUnderConstruction);

[self notifyObjectThatItIsReady: objectUnderConstruction];

return objectUnderConstruction;
}

Expand Down
4 changes: 4 additions & 0 deletions Source/JSObjectionUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ static void InjectDependenciesIntoProperties(JSObjectionInjector *injector, Clas

[object setValuesForKeysWithDictionary:propertiesDictionary];
}

if ([object respondsToSelector:@selector(awakeFromObjection)]) {
[object performSelector:@selector(awakeFromObjection)];
}
}

const struct JSObjectionUtils JSObjectionUtils = {
Expand Down
9 changes: 9 additions & 0 deletions Specs/BasicUsageSpecs.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@
assertThat(car.brakes, is(instanceOf([Brakes class])));
});

it(@"calls awakeFromObjection when injecting dependencies into properties of an existing instance", ^{
Car *car = [[Car alloc] init];

[[JSObjection defaultInjector] injectDependencies:car];

assertThatBool([car awake], equalToBool(YES));
assertThatBool([car.engine awake], equalToBool(YES));
});

it(@"defaults to returning a new instance", ^{
id thomas = [[JSObjection defaultInjector] getObject:[Engine class]];
id gordan = [[JSObjection defaultInjector] getObject:[Engine class]];
Expand Down

0 comments on commit b319097

Please sign in to comment.