lestathc / SOInjection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SOInjection

The helper lib for Objection framework (http://objection-framework.org/).

Functions

Autogenerated objection requirements

Define injectable property like, you have

@interface InjectableClassA : NSObject
@end
@interface InjectableClassB : NSObject
@end

@implementation InjectableClassA
objection_register_singleton(InjectableClassA)
@end

@implementation InjectableClassB
@end

@interface ViewController
@InjectSingltonProperty InjectableClassA *classA;
@InjectProperty InjectableClassB *classB;
@end

then the script will auto generate the category like

@implementation ViewController (__Objection__Autogen__)
objection_requires(@"classA",@"classB")
@end

NOTE, @InjectProperty will strong refer to the, and @InjectSingltonProperty will weak refer to the property. You may want to use @InjectSingltonProperty to avoid memory leak in some cases, like the child view controller may inject the context parent view controller (in next section), or a sington and another injectable object refers each other.

View Controller scoped injection

When we instantiate singletons in application object graph, they live in memory until the app is destroyed. But there are some singleton dependencies that are useful only when another object is alive. Like child view controllers may depends on parent view controller. Let the parent view controller conforms the

@protocol SOContextViewController <NSObject>
@end

which will create a new injector for the view controller.

Since the new injector inherits from application object graph, you need explictly bind instance or block in module if you still want to define singletons in application object graph.

About

License:MIT License


Languages

Language:Objective-C 72.3%Language:Python 27.2%Language:Ruby 0.5%