Skip to content

Commit

Permalink
New injections by factory instance are introduced (See #131).
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgarbarev committed Feb 13, 2014
1 parent 507518b commit 6476930
Show file tree
Hide file tree
Showing 22 changed files with 9,098 additions and 8,677 deletions.
2 changes: 1 addition & 1 deletion .scripts/pod-update-checksum.txt
@@ -1 +1 @@
38463b2339fd0679a7c0651c900a309479770104
94531e88dcaa6e213f04a19417fb9065151dd70e
16 changes: 16 additions & 0 deletions A-Typhoon.xcodeproj/project.pbxproj
Expand Up @@ -348,6 +348,10 @@
FA7A961B1895370900053EAE /* NSObject+PropertyInjection.h in Headers */ = {isa = PBXBuildFile; fileRef = FA7A96181895370900053EAE /* NSObject+PropertyInjection.h */; };
FA7A961C1895370900053EAE /* NSObject+PropertyInjection.m in Sources */ = {isa = PBXBuildFile; fileRef = FA7A96191895370900053EAE /* NSObject+PropertyInjection.m */; };
FA7A961D1895370900053EAE /* NSObject+PropertyInjection.m in Sources */ = {isa = PBXBuildFile; fileRef = FA7A96191895370900053EAE /* NSObject+PropertyInjection.m */; };
FA8AA3F318AD4055001B88CE /* TyphoonPropertyInjectedByComponentFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = FA8AA3F118AD4055001B88CE /* TyphoonPropertyInjectedByComponentFactory.h */; };
FA8AA3F418AD4055001B88CE /* TyphoonPropertyInjectedByComponentFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = FA8AA3F218AD4055001B88CE /* TyphoonPropertyInjectedByComponentFactory.m */; };
FA8AA3F718AD411C001B88CE /* TyphoonParameterInjectedByComponentFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = FA8AA3F518AD411C001B88CE /* TyphoonParameterInjectedByComponentFactory.h */; };
FA8AA3F818AD411C001B88CE /* TyphoonParameterInjectedByComponentFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = FA8AA3F618AD411C001B88CE /* TyphoonParameterInjectedByComponentFactory.m */; };
FA99165118983367000AC4B5 /* NSObject+DeallocNotification.h in Headers */ = {isa = PBXBuildFile; fileRef = FA99164F18983367000AC4B5 /* NSObject+DeallocNotification.h */; };
FA99165218983367000AC4B5 /* NSObject+DeallocNotification.h in Headers */ = {isa = PBXBuildFile; fileRef = FA99164F18983367000AC4B5 /* NSObject+DeallocNotification.h */; };
FA99165318983367000AC4B5 /* NSObject+DeallocNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = FA99165018983367000AC4B5 /* NSObject+DeallocNotification.m */; };
Expand Down Expand Up @@ -561,6 +565,10 @@
CAEF00E64F8B33A34E7E7E0D /* TyphoonComponentPostProcessor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TyphoonComponentPostProcessor.h; sourceTree = "<group>"; };
FA7A96181895370900053EAE /* NSObject+PropertyInjection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+PropertyInjection.h"; sourceTree = "<group>"; };
FA7A96191895370900053EAE /* NSObject+PropertyInjection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+PropertyInjection.m"; sourceTree = "<group>"; };
FA8AA3F118AD4055001B88CE /* TyphoonPropertyInjectedByComponentFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TyphoonPropertyInjectedByComponentFactory.h; sourceTree = "<group>"; };
FA8AA3F218AD4055001B88CE /* TyphoonPropertyInjectedByComponentFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TyphoonPropertyInjectedByComponentFactory.m; sourceTree = "<group>"; };
FA8AA3F518AD411C001B88CE /* TyphoonParameterInjectedByComponentFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TyphoonParameterInjectedByComponentFactory.h; sourceTree = "<group>"; };
FA8AA3F618AD411C001B88CE /* TyphoonParameterInjectedByComponentFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TyphoonParameterInjectedByComponentFactory.m; sourceTree = "<group>"; };
FA99164F18983367000AC4B5 /* NSObject+DeallocNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+DeallocNotification.h"; sourceTree = "<group>"; };
FA99165018983367000AC4B5 /* NSObject+DeallocNotification.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+DeallocNotification.m"; sourceTree = "<group>"; };
FA9916601898390E000AC4B5 /* TyphoonComponentsPool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TyphoonComponentsPool.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -800,6 +808,8 @@
BA7980FD63159528D9C7B729 /* TyphoonAbstractInjectedProperty.h */,
BA798A9F772D94ED724D741E /* TyphoonPropertyInjectedAsCollection.m */,
BA798AC05A2B92665E780091 /* TyphoonPropertyInjectedAsCollection.h */,
FA8AA3F118AD4055001B88CE /* TyphoonPropertyInjectedByComponentFactory.h */,
FA8AA3F218AD4055001B88CE /* TyphoonPropertyInjectedByComponentFactory.m */,
);
path = Properties;
sourceTree = "<group>";
Expand Down Expand Up @@ -1057,6 +1067,8 @@
BA7988C6445E2C71B781399C /* TyphoonAbstractInjectedParameter.h */,
BA7983A32BC2D2327FF04648 /* TyphoonParameterInjectedAsCollection.m */,
BA798DD1BD08B8691D33E992 /* TyphoonParameterInjectedAsCollection.h */,
FA8AA3F518AD411C001B88CE /* TyphoonParameterInjectedByComponentFactory.h */,
FA8AA3F618AD411C001B88CE /* TyphoonParameterInjectedByComponentFactory.m */,
);
path = Initializer;
sourceTree = "<group>";
Expand Down Expand Up @@ -1244,6 +1256,7 @@
6596DAE0189D806300B30708 /* TyphoonAssistedFactoryMethodBlockClosure.h in Headers */,
BA798268DF4E3622D436015F /* TyphoonPatcher.h in Headers */,
BA798AF0AA1673110FF60CA5 /* TyphoonPatchObjectFactory.h in Headers */,
FA8AA3F718AD411C001B88CE /* TyphoonParameterInjectedByComponentFactory.h in Headers */,
BA79802ECC87F8E422FC3D88 /* TyphoonFactoryProvider.h in Headers */,
BA798822E6832A737A063410 /* TyphoonAssistedFactoryDefinition.h in Headers */,
BA798075E0A02AB71898A854 /* TyphoonAssistedFactoryBase.h in Headers */,
Expand Down Expand Up @@ -1272,6 +1285,7 @@
BA798EE8514A848AC6EC4D47 /* TyphoonComponentFactory+TyphoonDefinitionRegisterer.h in Headers */,
BA7988F6752B4EECFB1DC0F6 /* TyphoonPropertyInjectionDelegate.h in Headers */,
75AB54AFCFB4B1CED0D65E4C /* TyphoonCircularDependencyTerminator.h in Headers */,
FA8AA3F318AD4055001B88CE /* TyphoonPropertyInjectedByComponentFactory.h in Headers */,
75AB5BA9A0A17ADE51EBEF62 /* TyphoonMethodSwizzler.h in Headers */,
75AB5921CEA2DAFD8FC95022 /* TyphoonJRMethodSwizzler.h in Headers */,
BA798D5253AF4D2856B53275 /* TyphoonTestUtils.h in Headers */,
Expand Down Expand Up @@ -1481,6 +1495,7 @@
46877CEE17D70B2200910D6A /* TyphoonTypeConvertedCollectionValue.m in Sources */,
FACBAABB18A60F4F006E493A /* TyphoonParameterInjectedByFactoryReference.m in Sources */,
BA79872DF8877EAE77B40A1C /* TyphoonStringUtils.m in Sources */,
FA8AA3F418AD4055001B88CE /* TyphoonPropertyInjectedByComponentFactory.m in Sources */,
FAD8269A1891513C009D9A27 /* TyphoonPropertyInjectedByFactoryReference.m in Sources */,
BA798DFF7B2C8B84F995D7B6 /* TyphoonPassThroughTypeConverter.m in Sources */,
BA7981D362FD3B1A948454F8 /* TyphoonPrimitiveTypeConverter.m in Sources */,
Expand Down Expand Up @@ -1527,6 +1542,7 @@
BA7981F1CAC3C59D8C7BE0DF /* TyphoonStackElement.m in Sources */,
BA79874BF022AA847BFE4733 /* TyphoonComponentFactory.m in Sources */,
BA7984FC182683B6DA08DB6F /* TyphoonParentReferenceHydratingPostProcessor.m in Sources */,
FA8AA3F818AD411C001B88CE /* TyphoonParameterInjectedByComponentFactory.m in Sources */,
BA7982950ACC08F1F91FBA05 /* NSInvocation+TCFInstanceBuilder.m in Sources */,
BA79856A1C1DBB588E701FF4 /* NSValue+TCFInstanceBuilder.m in Sources */,
BA798C345BD399FD7B3619E2 /* TyphoonAbstractInjectedParameter.m in Sources */,
Expand Down
7 changes: 7 additions & 0 deletions Source/Definition/Initializer/TyphoonInitializer.h
Expand Up @@ -119,6 +119,10 @@ To inject a class object:
*/
- (void)injectWithCollection:(void (^)(TyphoonParameterInjectedAsCollection *))collectionValues requiredType:(id)requiredType;

/**
* Injects TyphoonComponentFactory
*/
- (void)injectWithComponentFactory;

#pragma mark - injectParameterNamed:
- (void)injectParameterNamed:(NSString *)name withReference:(NSString *)reference;
Expand All @@ -142,6 +146,7 @@ To inject a class object:
- (void)injectParameterNamed:(NSString *)name asCollection:(void (^)(TyphoonParameterInjectedAsCollection *))collectionValues
requiredType:(id)requiredType;

- (void)injectWithComponentFactoryAsName:(NSString *)name;

#pragma mark - injectParameterAtIndex
/**
Expand All @@ -161,4 +166,6 @@ To inject a class object:

- (void)injectParameterAtIndex:(NSUInteger)index withObject:(id)value;

- (void)injectWithComponentFactoryAtIndex:(NSUInteger)index;

@end
18 changes: 18 additions & 0 deletions Source/Definition/Initializer/TyphoonInitializer.m
Expand Up @@ -20,6 +20,7 @@
#import "TyphoonParameterInjectedWithObjectInstance.h"
#import "TyphoonDefinition.h"
#import "TyphoonParameterInjectedAsCollection.h"
#import "TyphoonParameterInjectedByComponentFactory.h"

@implementation TyphoonInitializer

Expand Down Expand Up @@ -114,6 +115,12 @@ - (void)injectParameterNamed:(NSString *)name withObject:(id)value {
}];
}

- (void)injectWithComponentFactoryAsName:(NSString *)name {
[self injectParameterNamed:name success:^(NSInteger index) {
[self injectWithComponentFactoryAtIndex:index];
}];
}

- (void)injectParameterNamed:(NSString *)name success:(void (^)(NSInteger))success {
NSInteger index = [self indexOfParameter:name];
if (index == NSNotFound) {
Expand Down Expand Up @@ -170,6 +177,13 @@ - (NSString *)recoverySuggestionForMultipleMissingParameters {

#pragma mark injectParameterAtIndex:

- (void)injectWithComponentFactoryAtIndex:(NSUInteger)index {
if ([self canAddParameterAtIndex:index]) {
[self addParameter:[[TyphoonParameterInjectedByComponentFactory alloc] initWithParameterIndex:index]];
}
}


- (void)injectParameterAtIndex:(NSUInteger)index withReference:(NSString *)reference {
if ([self canAddParameterAtIndex:index]) {
[self addParameter:[[TyphoonParameterInjectedByReference alloc] initWithParameterIndex:index reference:reference]];
Expand Down Expand Up @@ -229,6 +243,10 @@ - (void)injectWithCollection:(void (^)(TyphoonParameterInjectedAsCollection *))c
[self injectParameterAtIndex:[self indexToAddParameter] asCollection:collectionValues requiredType:requiredType];
}

- (void)injectWithComponentFactory {
[self injectWithComponentFactoryAtIndex:[self indexToAddParameter]];
}

/* ====================================================================================================================================== */
#pragma mark - Block assembly

Expand Down
@@ -0,0 +1,19 @@
////////////////////////////////////////////////////////////////////////////////
//
// TYPHOON FRAMEWORK
// Copyright 2013, Jasper Blues & Contributors
// All Rights Reserved.
//
// NOTICE: The authors permit you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////


#import "TyphoonAbstractInjectedParameter.h"

@interface TyphoonParameterInjectedByComponentFactory : TyphoonAbstractInjectedParameter

- (instancetype)initWithParameterIndex:(NSUInteger)parameterIndex;

@end
@@ -0,0 +1,40 @@
////////////////////////////////////////////////////////////////////////////////
//
// TYPHOON FRAMEWORK
// Copyright 2013, Jasper Blues & Contributors
// All Rights Reserved.
//
// NOTICE: The authors permit you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////


#import "TyphoonParameterInjectedByComponentFactory.h"

@implementation TyphoonParameterInjectedByComponentFactory

/* ====================================================================================================================================== */
#pragma mark - Initialization

- (instancetype)initWithParameterIndex:(NSUInteger)parameterIndex {
self = [super init];
if (self) {
_index = parameterIndex;
}
return self;
}

/* ====================================================================================================================================== */
#pragma mark - Overrides

- (id)copyWithZone:(NSZone *)zone {
return [[TyphoonParameterInjectedByComponentFactory alloc] initWithParameterIndex:_index];
}

- (void)withFactory:(TyphoonComponentFactory *)factory setArgumentOnInvocation:(NSInvocation *)invocation {
[self setObject:factory forInvocation:invocation];
}


@end
@@ -0,0 +1,18 @@
////////////////////////////////////////////////////////////////////////////////
//
// TYPHOON FRAMEWORK
// Copyright 2013, Jasper Blues & Contributors
// All Rights Reserved.
//
// NOTICE: The authors permit you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

#import "TyphoonAbstractInjectedProperty.h"

@interface TyphoonPropertyInjectedByComponentFactory : TyphoonAbstractInjectedProperty

- (instancetype) initWithName:(NSString *)name;

@end
@@ -0,0 +1,34 @@
////////////////////////////////////////////////////////////////////////////////
//
// TYPHOON FRAMEWORK
// Copyright 2013, Jasper Blues & Contributors
// All Rights Reserved.
//
// NOTICE: The authors permit you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

#import "TyphoonPropertyInjectedByComponentFactory.h"

@implementation TyphoonPropertyInjectedByComponentFactory

/* ====================================================================================================================================== */
#pragma mark - Initialization

- (instancetype)initWithName:(NSString *)name {
self = [super init];
if (self) {
_name = name;
}
return self;
}

/* ====================================================================================================================================== */
#pragma mark - Overrides

- (id)withFactory:(TyphoonComponentFactory *)factory computeValueToInjectOnInstance:(id)instance {
return factory;
}

@end
28 changes: 22 additions & 6 deletions Source/Definition/Properties/TyphoonPropertyInjectedByType.m
Expand Up @@ -16,7 +16,7 @@
#import "TyphoonTypeDescriptor.h"
#import "TyphoonComponentFactory+InstanceBuilder.h"
#import "TyphoonDefinition.h"

#import "TyphoonAssembly.h"

@implementation TyphoonPropertyInjectedByType

Expand All @@ -36,14 +36,20 @@ - (id)initWithName:(NSString *)name {
#pragma mark - Overridden Methods

- (id)withFactory:(TyphoonComponentFactory *)factory computeValueToInjectOnInstance:(id)instance {
id value = nil;
TyphoonTypeDescriptor *type = [instance typeForPropertyWithName:self.name];
TyphoonDefinition *definition = [factory definitionForType:[type classOrProtocol]];

[factory evaluateCircularDependency:definition.key propertyName:self.name instance:instance];
if (![factory propertyIsCircular:self onInstance:instance]) {
return [factory componentForKey:definition.key];
if ([self isComponentFactoryType:type]) {
value = factory;
} else {
TyphoonDefinition *definition = [factory definitionForType:[type classOrProtocol]];
[factory evaluateCircularDependency:definition.key propertyName:self.name instance:instance];
if (![factory propertyIsCircular:self onInstance:instance]) {
value = [factory componentForKey:definition.key];
}
}
return nil;

return value;
}

/* ====================================================================================================================================== */
Expand All @@ -53,4 +59,14 @@ - (id)copyWithZone:(NSZone *)zone {
return [[TyphoonPropertyInjectedByType alloc] initWithName:[self.name copy]];
}

- (BOOL)isComponentFactoryType:(TyphoonTypeDescriptor *)type {
BOOL isFactoryClass = NO;

if (type.typeBeingDescribed) {
isFactoryClass = [type.typeBeingDescribed isSubclassOfClass:[TyphoonComponentFactory class]] || [type.typeBeingDescribed isSubclassOfClass:[TyphoonAssembly class]];
}

return isFactoryClass;
}

@end
5 changes: 5 additions & 0 deletions Source/Definition/TyphoonDefinition.h
Expand Up @@ -251,6 +251,11 @@ typedef void(^TyphoonDefinitionBlock)(TyphoonDefinition *definition);
*/
- (void)injectProperty:(SEL)selector withObjectInstance:(id)instance;

/**
* Injects property with TyphoonComponentFactory
*/
- (void)injectPropertyWithComponentFactory:(SEL)selector;

/**
* Injects property with the value represented by the given text. The text will be used to create an instance of a class matching the
* required type.
Expand Down
7 changes: 6 additions & 1 deletion Source/Definition/TyphoonDefinition.m
Expand Up @@ -20,9 +20,9 @@
#import "TyphoonPropertyInjectedAsCollection.h"
#import "TyphoonPropertyInjectedAsObjectInstance.h"
#import "TyphoonPropertyInjectedByFactoryReference.h"
#import "TyphoonPropertyInjectedByComponentFactory.h"
#import "TyphoonDefinition+Infrastructure.h"


@implementation TyphoonDefinition

/* ====================================================================================================================================== */
Expand Down Expand Up @@ -126,6 +126,11 @@ - (void)injectProperty:(SEL)withSelector asCollection:(void (^)(TyphoonPropertyI
[_injectedProperties addObject:propertyInjectedAsCollection];
}

- (void)injectPropertyWithComponentFactory:(SEL)selector {
TyphoonPropertyInjectedByComponentFactory *propertyInjection = [[TyphoonPropertyInjectedByComponentFactory alloc] initWithName:NSStringFromSelector(selector)];
[_injectedProperties addObject:propertyInjection];
}

- (void)setInitializer:(TyphoonInitializer *)initializer {
_initializer = initializer;
[_initializer setDefinition:self];
Expand Down
10 changes: 10 additions & 0 deletions Tests/CoverageFixer.m
@@ -1,6 +1,16 @@
////////////////////////////////////////////////////////////////////////////////
//
// TYPHOON FRAMEWORK
// Copyright 2014, Jasper Blues & Contributors
// All Rights Reserved.
//
// NOTICE: The authors permit you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// TYPHOON FRAMEWORK
// Copyright 2013, Jasper Blues & Contributors
// All Rights Reserved.
//
Expand Down
Expand Up @@ -16,4 +16,12 @@

- (id)injectionAwareObject;

- (id)injectionByProperty;

- (id)injectionByInitialization;

- (id)injectionByPropertyAssemblyType;

- (id)injectionByPropertyFactoryType;

@end

0 comments on commit 6476930

Please sign in to comment.