Latest 1.0.1
Homepage https://github.com/mr-noone/easy-di-kit
License MIT
Platforms ios 8.0
Authors

EasyDIKit is an Objective-C dependency injection framework for iOS.

Installation

Installation through CocoaPods.

platform :ios, '8.0'

target 'YourTarget' do
    pod 'EasyDIKit', '~> 1.0.0'
end

Usage

First, create a sub-class of DIAssembly.

@interface SomeAssembly : DIAssembly

- (Person *)commonPerson;
- (Person *)commonSingletonPerson;

@end

By default object is instantiated by calling new.

@implementation SomeAssembly

- (Person *)commonPerson {
    return [DIFactory instanceOfClass:Person.class];
}

- (Person *)commonSingletonPerson {
    // This method return a singleton of class
    return [DIFactory singletonOfClass:Person.class];
}

@end

Create objects using your own initializers with DIFactoryInitializer block.

@implementation SomeAssembly

- (Person *)commonPerson {
    DIFactoryInitializer initializer = ^(DIInitializer *initializer) {
        [initializer setSelector:@selector(initWithFirstName:lastName:age:)];
        [initializer injectParameter:@"John"];
        [initializer injectParameter:@"Smith"];
        // To inject a primitive, wrap it into 'NSNumber' or 'NSValue'
        [initializer injectParameter:@21];
    };

    return [DIFactory instanceOfClass:Person.class
                          initializer:initializer
                           injections:nil];
}

@end

Inject properties using DIFactoryInjections block.

@implementation SomeAssembly

- (Person *)commonPerson {
    DIFactoryInjections injections = ^(DIInjection *injections) {
        [injections injectProperty:@selector(firstName) with:@"John"];
        [injections injectProperty:@selector(lastName) with:@"Smith"];
        // To inject a primitive, wrap it into 'NSNumber' or 'NSValue'
        [injections injectProperty:@selector(age) with:@21];
    };

    return [DIFactory instanceOfClass:Person.class
                          initializer:nil
                           injections:injections];
}

@end

Inject method using DIFactoryInjections block.

@implementation SomeAssembly

- (Person *)commonPerson {
    DIInjectionParameters parameters = ^(DIMethod *method) {
        [method injectParameter:@"John"];
    };

    DIFactoryInjections injections = ^(DIInjection *injections) {
        [injections injectMethod:@selector(setFirstName:)
                      parameters:parameters];
    };

    return [DIFactory instanceOfClass:Person.class
                          initializer:nil
                           injections:injections];
}

@end

Obtain objects as follows:

Person *person = [SomeAssembly.assembly commonPerson];

Property injects automatically if it is subclassed form DIAssembly.

@interface SomeAssembly : DIAssembly
@end

@interface AppAssembly : DIAssembly

// This property inject automatically
@property (strong, nonatomic) SomeAssembly *someAssembly;

@end

License

MIT license. See the LICENSE file for details.

Latest podspec

{
    "name": "EasyDIKit",
    "version": "1.0.1",
    "summary": "EasyDIKit is an Objective-C dependency injection framework for iOS.",
    "homepage": "https://github.com/mr-noone/easy-di-kit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Aleksey Zgurskiy": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/mr-noone/easy-di-kit.git",
        "tag": "1.0.1"
    },
    "source_files": "EasyDIKit/EasyDIKit/**/*.{h,m}",
    "prefix_header_file": "EasyDIKit/EasyDIKit/Support Files/EasyDIKit.pch"
}

Pin It on Pinterest

Share This