Skip to content

Commit

Permalink
WeakSingleton scope is almost done
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgarbarev committed Jan 28, 2014
1 parent 4d90a1c commit fc4cbf6
Show file tree
Hide file tree
Showing 16 changed files with 459 additions and 21 deletions.
40 changes: 39 additions & 1 deletion A-Typhoon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@
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 */; };
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 */; };
FA99165418983367000AC4B5 /* NSObject+DeallocNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = FA99165018983367000AC4B5 /* NSObject+DeallocNotification.m */; };
FA9916611898390E000AC4B5 /* TyphoonComponentsPool.h in Headers */ = {isa = PBXBuildFile; fileRef = FA9916601898390E000AC4B5 /* TyphoonComponentsPool.h */; };
FA9916621898390E000AC4B5 /* TyphoonComponentsPool.h in Headers */ = {isa = PBXBuildFile; fileRef = FA9916601898390E000AC4B5 /* TyphoonComponentsPool.h */; };
FA99166518983986000AC4B5 /* TyphoonWeekComponentsPool.h in Headers */ = {isa = PBXBuildFile; fileRef = FA99166318983986000AC4B5 /* TyphoonWeekComponentsPool.h */; };
FA99166618983986000AC4B5 /* TyphoonWeekComponentsPool.h in Headers */ = {isa = PBXBuildFile; fileRef = FA99166318983986000AC4B5 /* TyphoonWeekComponentsPool.h */; };
FA99166718983986000AC4B5 /* TyphoonWeekComponentsPool.m in Sources */ = {isa = PBXBuildFile; fileRef = FA99166418983986000AC4B5 /* TyphoonWeekComponentsPool.m */; };
FA99166818983986000AC4B5 /* TyphoonWeekComponentsPool.m in Sources */ = {isa = PBXBuildFile; fileRef = FA99166418983986000AC4B5 /* TyphoonWeekComponentsPool.m */; };
FAD826981891513C009D9A27 /* TyphoonPropertyInjectedByFactoryReference.h in Headers */ = {isa = PBXBuildFile; fileRef = FAD826961891513C009D9A27 /* TyphoonPropertyInjectedByFactoryReference.h */; };
FAD826991891513C009D9A27 /* TyphoonPropertyInjectedByFactoryReference.h in Headers */ = {isa = PBXBuildFile; fileRef = FAD826961891513C009D9A27 /* TyphoonPropertyInjectedByFactoryReference.h */; };
FAD8269A1891513C009D9A27 /* TyphoonPropertyInjectedByFactoryReference.m in Sources */ = {isa = PBXBuildFile; fileRef = FAD826971891513C009D9A27 /* TyphoonPropertyInjectedByFactoryReference.m */; };
Expand Down Expand Up @@ -532,6 +542,11 @@
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>"; };
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>"; };
FA99166318983986000AC4B5 /* TyphoonWeekComponentsPool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TyphoonWeekComponentsPool.h; sourceTree = "<group>"; };
FA99166418983986000AC4B5 /* TyphoonWeekComponentsPool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TyphoonWeekComponentsPool.m; sourceTree = "<group>"; };
FAD826961891513C009D9A27 /* TyphoonPropertyInjectedByFactoryReference.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TyphoonPropertyInjectedByFactoryReference.h; sourceTree = "<group>"; };
FAD826971891513C009D9A27 /* TyphoonPropertyInjectedByFactoryReference.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TyphoonPropertyInjectedByFactoryReference.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -703,6 +718,8 @@
FA7A96191895370900053EAE /* NSObject+PropertyInjection.m */,
BA798479971ACE88BD0EEBDF /* NSObject+TyphoonIntrospectionUtils.h */,
BA798263556BF9A8D3735540 /* NSObject+TyphoonIntrospectionUtils.m */,
FA99164F18983367000AC4B5 /* NSObject+DeallocNotification.h */,
FA99165018983367000AC4B5 /* NSObject+DeallocNotification.m */,
BA7989B103528037045BF026 /* TyphoonIntrospectionUtils.h */,
BA7984898252E6336CCA405B /* TyphoonIntrospectionUtils.m */,
BA798D90E444A0899D50CD00 /* TyphoonIntrospectiveNSObject.h */,
Expand Down Expand Up @@ -973,15 +990,16 @@
isa = PBXGroup;
children = (
BA7984C2E9988794FC0166CB /* Xml */,
BA7982DFFB32EDBAE645CC9E /* TyphoonComponentFactory.h */,
BA7984DEE39286F762905EFA /* Block */,
BA798319486DFF3FA4625F22 /* Internal */,
75AB596E7ACCCA9D39B9168B /* TyphoonDefinitionRegisterer.m */,
75AB5622319F71FB5D11B005 /* TyphoonDefinitionRegisterer.h */,
BA798A65EC8ABD993B2BB848 /* TyphoonComponentFactoryAware.h */,
BA79873ECC78B638312DB9FD /* Provider */,
BA79876FCB0ED64706C9C817 /* TyphoonPropertyInjectionDelegate.h */,
BA7982DFFB32EDBAE645CC9E /* TyphoonComponentFactory.h */,
BA7985C9F3FF4D1EE99E9818 /* TyphoonComponentFactory.m */,
FA99165F189838F9000AC4B5 /* Pool */,
);
path = Factory;
sourceTree = "<group>";
Expand Down Expand Up @@ -1040,6 +1058,16 @@
path = TestUtils;
sourceTree = "<group>";
};
FA99165F189838F9000AC4B5 /* Pool */ = {
isa = PBXGroup;
children = (
FA9916601898390E000AC4B5 /* TyphoonComponentsPool.h */,
FA99166318983986000AC4B5 /* TyphoonWeekComponentsPool.h */,
FA99166418983986000AC4B5 /* TyphoonWeekComponentsPool.m */,
);
path = Pool;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand All @@ -1057,6 +1085,7 @@
4BC6492417A20BD7007F0463 /* TyphoonPropertyInjectedByType.h in Headers */,
4BC6492517A20BD7007F0463 /* TyphoonPropertyInjectedWithStringRepresentation.h in Headers */,
4BC6492717A20BD7007F0463 /* TyphoonInitializer.h in Headers */,
FA9916621898390E000AC4B5 /* TyphoonComponentsPool.h in Headers */,
466CC667185D589600742220 /* TyphoonUIColorTypeConverter.h in Headers */,
4BC6492817A20BD7007F0463 /* TyphoonInjectedParameter.h in Headers */,
4BC6492917A20BD7007F0463 /* TyphoonParameterInjectedByReference.h in Headers */,
Expand Down Expand Up @@ -1104,6 +1133,8 @@
BA798619A135767B6EA0D984 /* TyphoonAssistedFactoryBase.h in Headers */,
BA798C17092487AF9092BB04 /* TyphoonAssistedFactoryMethodCreator.h in Headers */,
BA798121997C3D8182725BB2 /* TyphoonAssistedFactoryCreator.h in Headers */,
FA99166618983986000AC4B5 /* TyphoonWeekComponentsPool.h in Headers */,
FA99165218983367000AC4B5 /* NSObject+DeallocNotification.h in Headers */,
BA798AB75EF5AE936CB4189F /* TyphoonAssistedFactoryCreatorOneFactory.h in Headers */,
BA79854874204FA3B863F0A5 /* TyphoonAssistedFactoryCreatorManyFactories.h in Headers */,
BA79837685E53C4E3D352BC6 /* TyphoonAssistedFactoryCreatorImplicit.h in Headers */,
Expand Down Expand Up @@ -1155,6 +1186,7 @@
BA7983A5AB140D6C97FCD503 /* TyphoonComponentFactory.h in Headers */,
BA798925FDAC1BC6E2937A2C /* TyphoonPropertyInjectedByReference.h in Headers */,
BA798C2625716A576AD32B0D /* TyphoonPropertyInjectedByType.h in Headers */,
FA9916611898390E000AC4B5 /* TyphoonComponentsPool.h in Headers */,
BA79827EEB8CA87219EE5DC1 /* TyphoonPropertyInjectedWithStringRepresentation.h in Headers */,
BA79899502CBAEE235B62757 /* TyphoonInitializer.h in Headers */,
BA7986F5C5D07F9A92B7B1CE /* TyphoonInjectedParameter.h in Headers */,
Expand All @@ -1175,6 +1207,7 @@
BA798097479D73266D1D3679 /* TyphoonAssembly.h in Headers */,
BA79897DD52D123AC065C637 /* TyphoonBlockComponentFactory.h in Headers */,
BA7989A288AA5FD437CFF984 /* TyphoonAutowire.h in Headers */,
FA99166518983986000AC4B5 /* TyphoonWeekComponentsPool.h in Headers */,
BA7981F6247963CF6E1B207C /* TyphoonShorthand.h in Headers */,
BA798173C5D4C7590346B9C8 /* TyphoonPropertyInjectedAsCollection.h in Headers */,
BA798057855D41E78C217B42 /* TyphoonPropertyInjectedAsObjectInstance.h in Headers */,
Expand All @@ -1201,6 +1234,7 @@
BA798822E6832A737A063410 /* TyphoonAssistedFactoryDefinition.h in Headers */,
BA798075E0A02AB71898A854 /* TyphoonAssistedFactoryBase.h in Headers */,
BA798526D89FF6FBADDAFF24 /* TyphoonAssistedFactoryMethodCreator.h in Headers */,
FA99165118983367000AC4B5 /* NSObject+DeallocNotification.h in Headers */,
BA79847EB9D7645F2DBE79EA /* TyphoonAssistedFactoryCreator.h in Headers */,
BA7988FC7C5C6E21097DDE62 /* TyphoonAssistedFactoryCreatorOneFactory.h in Headers */,
BA7982B99BAF8B04293CCC26 /* TyphoonAssistedFactoryCreatorManyFactories.h in Headers */,
Expand Down Expand Up @@ -1318,6 +1352,7 @@
4BC6490017A20BD7007F0463 /* TyphoonPropertyInjectedByType.m in Sources */,
4BC6490117A20BD7007F0463 /* TyphoonPropertyInjectedWithStringRepresentation.m in Sources */,
4BC6490217A20BD7007F0463 /* TyphoonInitializer.m in Sources */,
FA99166818983986000AC4B5 /* TyphoonWeekComponentsPool.m in Sources */,
4BC6490317A20BD7007F0463 /* TyphoonParameterInjectedByReference.m in Sources */,
4BC6490417A20BD7007F0463 /* TyphoonParameterInjectedWithStringRepresentation.m in Sources */,
4BC6490517A20BD7007F0463 /* TyphoonDefinition.m in Sources */,
Expand Down Expand Up @@ -1364,6 +1399,7 @@
FA7A961D1895370900053EAE /* NSObject+PropertyInjection.m in Sources */,
BA798F90FEC1C4F61DB99D6E /* TyphoonAssistedFactoryMethodClosure.m in Sources */,
BA79888B0D2AB76A2ABDDB0B /* TyphoonAssistedFactoryBase+TyphoonFactoryMethodClosure.m in Sources */,
FA99165418983367000AC4B5 /* NSObject+DeallocNotification.m in Sources */,
BA798166B307526560F59BD4 /* TyphoonAssistedFactoryMethodBlock.m in Sources */,
BA7985D2AE9A8486CF305866 /* TyphoonAssistedFactoryMethodBlockCreator.m in Sources */,
BA7986149A3BA0CF794B9C2A /* TyphoonPropertyPlaceholderConfigurer.m in Sources */,
Expand Down Expand Up @@ -1415,6 +1451,7 @@
BA798917A7860D9B8DC321BE /* TyphoonPropertyInjectedAsCollection.m in Sources */,
B594F880174DF32E00BF5DC5 /* TyphoonParameterInjectedWithObjectInstance.m in Sources */,
BA7989AECA7E0892DF83BBCD /* TyphoonPropertyInjectedAsObjectInstance.m in Sources */,
FA99165318983367000AC4B5 /* NSObject+DeallocNotification.m in Sources */,
46877CE417D70B2200910D6A /* TyphoonInjectedAsCollection.m in Sources */,
46877CE817D70B2200910D6A /* TyphoonByReferenceCollectionValue.m in Sources */,
FA7A961C1895370900053EAE /* NSObject+PropertyInjection.m in Sources */,
Expand All @@ -1431,6 +1468,7 @@
75AB5C334CEC9F0104368CF5 /* TyphoonAssemblyAdviser.m in Sources */,
75AB531A26C980E9FF6A445B /* TyphoonAssemblyDefinitionBuilder.m in Sources */,
BA79842B467B10683D2CF7F8 /* TyphoonURLUtils.m in Sources */,
FA99166718983986000AC4B5 /* TyphoonWeekComponentsPool.m in Sources */,
BA7982BD05787F18973620FE /* TyphoonPatcher.m in Sources */,
BA7987A8CBF07731831E1822 /* TyphoonPatchObjectFactory.m in Sources */,
BA7987FC00A60951A729ABAB /* TyphoonFactoryProvider.m in Sources */,
Expand Down
7 changes: 4 additions & 3 deletions Source/Definition/TyphoonDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
*/
typedef enum
{
TyphoonScopeObjectGraph = 1 << 0,
TyphoonScopePrototype = 1 << 1,
TyphoonScopeSingleton = 1 << 2,
TyphoonScopeObjectGraph = 1 << 0,
TyphoonScopePrototype = 1 << 1,
TyphoonScopeSingleton = 1 << 2,
TyphoonScopeWeakSingleton = 1 << 3
} TyphoonScope;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,18 @@ @implementation TyphoonComponentFactory (InstanceBuilder)

- (id)buildInstanceWithDefinition:(TyphoonDefinition*)definition
{
__autoreleasing id <TyphoonIntrospectiveNSObject> instance = [self allocateInstance:instance withDefinition:definition];
__autoreleasing id <TyphoonIntrospectiveNSObject> instance = [self allocateInstanceWithDefinition:definition];
[_stack push:[TyphoonStackElement itemWithKey:definition.key instance:instance]];
instance = [self injectInstance:instance withDefinition:definition];
instance = [self postProcessInstance:instance];
[_stack pop];
return instance;
}

- (id)allocateInstance:(id)instance withDefinition:(TyphoonDefinition*)definition
- (id)allocateInstanceWithDefinition:(TyphoonDefinition*)definition
{
id instance = nil;

if (definition.factoryReference)
{
// misleading - this is not the instance. this is an instance of a separate class that will create the instance of the class we care
Expand All @@ -79,6 +81,7 @@ - (id)allocateInstance:(id)instance withDefinition:(TyphoonDefinition*)definitio
else
{
// this is an instance, needing later init.
/* FIXME: sending init on another line than alloc is wrong, see apple docs */
instance = [definition.type alloc];
}

Expand Down
22 changes: 22 additions & 0 deletions Source/Factory/Pool/TyphoonComponentsPool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// TyphoonComponentsPool.h
// A-Typhoon
//
// Created by Aleksey Garbarev on 29.01.14.
// Copyright (c) 2014 Jasper Blues. All rights reserved.
//

#import <Foundation/Foundation.h>

/** Methods from NSMutableDictionary which used in componentsPool. Created to maintain custom TyphoonWeekComponentsPool */

@protocol TyphoonComponentsPool <NSObject>

- (void) setObject:(id)object forKey:(id<NSCopying>)aKey;
- (id) objectForKey:(id<NSCopying>)aKey;

- (NSArray *) allValues;

- (void) removeAllObjects;

@end
14 changes: 14 additions & 0 deletions Source/Factory/Pool/TyphoonWeekComponentsPool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// TyphoonWeekComponentsPool.h
// A-Typhoon
//
// Created by Aleksey Garbarev on 29.01.14.
// Copyright (c) 2014 Jasper Blues. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "TyphoonComponentsPool.h"

@interface TyphoonWeekComponentsPool : NSObject <TyphoonComponentsPool>

@end
55 changes: 55 additions & 0 deletions Source/Factory/Pool/TyphoonWeekComponentsPool.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// TyphoonWeekComponentsPool.m
// A-Typhoon
//
// Created by Aleksey Garbarev on 29.01.14.
// Copyright (c) 2014 Jasper Blues. All rights reserved.
//

#import "TyphoonWeekComponentsPool.h"
#import "NSObject+DeallocNotification.h"

@implementation TyphoonWeekComponentsPool {
NSMutableDictionary *dictionaryWithUnretainedObjects;
}

- (id)init
{
self = [super init];
if (self) {
CFDictionaryValueCallBacks callbacks = {0, NULL, NULL, NULL, NULL};
dictionaryWithUnretainedObjects = (__bridge_transfer id)CFDictionaryCreateMutable(NULL,
0,
&kCFTypeDictionaryKeyCallBacks,
&callbacks);
}
return self;
}

- (void) setObject:(id)object forKey:(id<NSCopying>)aKey
{
__weak typeof (dictionaryWithUnretainedObjects) weakDict = dictionaryWithUnretainedObjects;

[object setDeallocNotificationInBlock:^{
[weakDict removeObjectForKey:aKey];
}];

[dictionaryWithUnretainedObjects setObject:object forKey:aKey];
}

- (id) objectForKey:(id<NSCopying>)aKey
{
return [dictionaryWithUnretainedObjects objectForKey:aKey];
}

- (NSArray *) allValues
{
return [dictionaryWithUnretainedObjects allValues];
}

- (void) removeAllObjects
{
[dictionaryWithUnretainedObjects removeAllObjects];
}

@end
8 changes: 5 additions & 3 deletions Source/Factory/TyphoonComponentFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#import <Foundation/Foundation.h>
#import "TyphoonComponentFactoryPostProcessor.h"
#import "TyphoonComponentsPool.h"

@class TyphoonDefinition;
@class TyphoonCallStack;
Expand All @@ -28,9 +29,10 @@
@interface TyphoonComponentFactory : NSObject
{
NSMutableArray* _registry;
NSMutableDictionary* _singletons;
NSMutableDictionary* _objectGraphSharedInstances;

id<TyphoonComponentsPool> _singletons;
id<TyphoonComponentsPool> _objectGraphSharedInstances;
id<TyphoonComponentsPool> _weakSingletons;

TyphoonCallStack* _stack;
NSMutableArray* _factoryPostProcessors;
NSMutableArray* _componentPostProcessors;
Expand Down
Loading

0 comments on commit fc4cbf6

Please sign in to comment.