Latest 0.0.3
Homepage https://github.com/nsrandom/injector
License MIT

Injector provides a lightweight framework for binding and injecting services at runtime.

A "service" is composed of an API and an implementation of that API. There can be multiple implementations for a given API.

Example

If you have an API

// HelloService.h
@protocol HelloService <NSObject>
- (void)sayHello;
@end

and an implementation for the above

// HelloNSLogger.h
@interface HelloNSLogger <HelloService>
@end

// HelloNSLogger.m
@implementation HelloNSLogger
- (void)sayHello {
  NSLog(@"Hello");
}
@end

Injector lets you bind the implementation to the service injector.

[[NSRInjector sharedInstance] bindImplClass:[HelloNSLogger class] 
                                  toService:@protocol(HelloService)
                                withOptions:[NSRInjectorOptions lazySingleton]];

// Shortcut macro for the above
NSR_BIND(HelloNSLogger, HelloService, [NSRInjectorOptions lazySingleton]);

And then, a client of HelloService can obtain an instance of HelloService via

id<HelloService> helloService = [[NSRInjector sharedInstance] inject:@protocol(HelloService)];
// OR
id<HelloService> helloService = NSR_INJECT(HelloService);

Latest podspec

{
    "name": "Injector",
    "version": "0.0.3",
    "summary": "Injector provides a lightweight framework for binding and injecting services at runtime.",
    "description": "                   Injector provides a lightweight framework for binding and injecting services at runtime.nn                   ### Why use Injector?n                   * Divide your code into standalone components.n                   * Swap implementations of these components easily.nn                   See https://github.com/nsrandom/injector for a more detailed description and example code.n",
    "homepage": "https://github.com/nsrandom/injector",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": "NSRandom",
    "social_media_url": "https://twitter.com/nsrandom",
    "source": {
        "git": "https://github.com/nsrandom/injector.git",
        "tag": "0.0.3"
    },
    "source_files": [
        "Injector",
        "Injector/**/*.{h,m}"
    ],
    "public_header_files": "Injector/**/*.h",
    "requires_arc": true
}

Pin It on Pinterest

Share This