Cocoa / Cocoa Touch Dependency Injection framework with features for simpler TDD
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
Kiwi @ b34a154

Injective framework

The purpose of this framework is to provide a simple dependency injection framework for iOS/Mac applications.

Injective provides facilities for automatic connection of class instances by resolving properties dependencies. Additionally, Injective verifies that all required data is passed to instance for it to function correctly.

Injective supports factory-like object creation and singleton object creation.


Git version

(For git users only) Add Injective as a submodule

If you're using git as your project's scm, add Injective as a submodue:

git submodule add

(For all others) Download Injective source

Download Injective source code from and unzip it to your project root directory.

Add Injective project to your workspace

Add Injective project to Project navigator (this will create a workspace if you don't have one). To do this, drag Injective.xcodeproj from the Finder to the very bottom of your project navigator panel.

If you don't have a workspace yet, you will be asked: "Do you want to save this project in a new workspace?". Save it.

Add public headers to search path

Open your project's build settings and add Injective/Headers to Header Search paths. If you followed step 0, it's as simple as adding $(PROJECT_DIR)/Injective/Injective/Headers

(optional) Add Injective as a global header

Add the following line to your project's precompiled header (pch file): #import "InjectiveContext.h":

#import "IJContext.h"

This will allow you to use Injective without requiring you to #import it everywhere.

Precompiled version

There is a target to build Injective.framework, however at the current point there is no stable release. Precompiled builds would be added later, for now it's suggested that you use a recent git checkout.


Configuring a default context

All the helpers require a global context to be set up. You can specify one with:

IJContext *defaultContext = [[IJContext alloc] init];
[IJContext setDefaultContext:defaultContext];

Where to do that? As soon as you can. You can use -application:didFinishLaunchingWithOptions: of the application delegate in the iOS projects.

Registering a singleton class

To register a class you need to use +registerClass:instantinationMode: method of IJContext class:

IJContext *myContext = [[IJContext alloc] init];
[myContext registerClass:[MyAPIController class]

Then, you can get an instance of the class with the following code:

MyAPIController *api = [myContext instantinateClass:[MyAPIController class]

Note: You can also use the injective_register_singleton macro in your class implementation:

@implementation MyAPIController




Registering a common class

You can register a common class using IJContextInstantinationModeFactory. This way, Injective will create a new instance of the class each time you instantiate it:

IJContext *myContext = [[IJContext alloc] init];
 registerClass:[MyDetailViewController class]

In this mode, you can pass additional properties that would be mapped by KVC:

NSDictionary *d = [NSDictionary dictionaryWithObjectsAndKeys:
                   items, @"items",
MyDetailViewController *viewController = [myContext
                                          instantinateClass:[MyDetailViewController class] 

Note: You can also use the injective_register macro in your class implementation:

@implementation MyDetailViewController




Specifying dependencies

To make Injective actually useful, you need to specify a set of properties, that your class requires. You can do this via +injective_requredProperties method:

@interface MyDetailViewController : UIViewController

@property (nonatomic, strong) MyAPIController *apiController;


@implementation MyDetailViewController


+ (NSSet *)injective_requredProperties
    return [NSSet setWithObject:@"apiController"];


There's another handy macro for you -- injective_requires, that does the same job:

@implementation MyDetailViewController



Instantiation helpers

You can instantiate any object in default context using the following class method of NSObject's category:

MyDetailViewController *viewController = [MyDetailViewController injectiveInstantiate];


Injective is a MIT-licensed framework. See details in LICENSE file.


Flattr this git repo


Injective framework is originally written by Vladimir "Farcaller" Pouzanov <>.

A few ideas are based on Objection framework (

Bugs / Suggestions

I'm always open to communication. Please file a ticket via github issues system at