Aspyct.org

APServiceBox: cross-dependency injection

| Comments

APServiceBox had a little update today (v12.08.29). Now, when you call the fill: method for the first time, APServiceBox will first scan all its dependencies and fill them as well. Thus, you can have dependencies that depend on each other. All you have to do is register both dependencies into the container before you fill: your first object. Read on for an example.

StorageManager
1
2
3
@interface StorageManager

@end
PreferenceManager
1
2
3
4
5
@interface PreferenceManager

@property (strong, nonatomic) StorageManager *storageManager;

@end
Usage example
1
2
3
4
5
6
7
8
9
APServiceBox *box = [[APServiceBox alloc] init];
[box registerDependency:preferenceManger as:@"preferenceManager"];
[box registerDependency:storageManger as:@"storageManager"];

// And if you invoke...
[box fill:myObject];

// ...then the following is true:
preferenceManager.storageManager == storageManager;

More about APServiceBox.

Comments