Dear reader,

This site finally got its much-needed overhaul. I tried to keep existing pages at their original URLs.
Should you find an error, please do tell me at contact@aspyct.org.
Feel free to visit the new website, which may contain more documentation pertaining to your search.

Thank you for visiting aspyct.org, I hope you'll find what you're looking for.

Old Aspyct.org blog

 or  go to the new site.

APServiceBox: cross-dependency injection

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.