Skip to content

Commit

Permalink
updating readme to reflect re-factoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jdewind committed Dec 7, 2010
1 parent f3e7452 commit 00d10d6
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions README.md
Expand Up @@ -28,20 +28,51 @@ A class can be registered with objection using the macros *objection_register* o
@property(nonatomic) BOOL awake; @property(nonatomic) BOOL awake;


@implementation Car @implementation Car
objection_register(@"Car") objection_register(Car)
objection_requires(@"engine", @"brakes") objection_requires(@"engine", @"brakes")
@synthesize engine, brakes, awake; @synthesize engine, brakes, awake;
@end @end


### Registering Objects


Objection supports associating an object outside the context of Objection with a class. ### Fetching Objects from Objection

An object can be fetched from objection by creating an injector and then asking for an instance of particular class. An injector manages its own object context. Which means that a singleton is per injector and is not necessarily a *true* singleton.

- (void)someMethod {
ObjectionInjector *injector = [Objection createInjector];
id car = [injector getObject:[Car class]];
}

A global injector can registered with Objection which can be used throughout your application or library.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
ObjectionInjector *injector = [Objection createInjector];
[Objection setGlobalInjector:injector];
}

- (void)viewDidLoad {
id myModel = [[Objection globalInjector] getObject:[MyModel class]];
}

### Registering Instances

Objection supports associating an object outside the context of Objection by configuring an ObjectionModule.


### Example ### Example
@interface MyAppModule : ObjectionModule {
}
@end
@implementation MyAppModule
- (void)configure {
[self bind:[UIApplication sharedApplication] toClass:[UIApplication class]];
}
@end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[ObjectionInjector ObjectionInjector *injector = [Objection createInjector:[[[MyAppModule alloc] init] autorelease]];
registerObject:[UIApplication sharedApplication] [Objection setGlobalInjector:injector];
forClass:[UIApplication class]];
} }


### Instance Creation Notification ### Instance Creation Notification
Expand All @@ -59,12 +90,6 @@ If an object is interested in knowing when it has been fully instantiated by obj
@end @end


### Fetching Objects from Objection

- (void)someMethod {
id car = [ObjectionInjector getObject:[Car class]];
}

### TODO ### TODO


* Migrate to using a module specific context rather than a shared global context (similar to Guice) * Migrate to using a module specific context rather than a shared global context (similar to Guice)
Expand Down

0 comments on commit 00d10d6

Please sign in to comment.