{"id":32109224,"url":"https://github.com/openbakery/obinjector","last_synced_at":"2026-03-13T13:33:20.010Z","repository":{"id":16054498,"uuid":"18798629","full_name":"openbakery/OBInjector","owner":"openbakery","description":"The OBInjector is a very small and simple dependency injector for Objective-C that does property injection.","archived":false,"fork":false,"pushed_at":"2025-05-12T11:43:15.000Z","size":234,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-20T12:58:46.865Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openbakery.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-04-15T12:09:15.000Z","updated_at":"2025-05-12T11:40:33.000Z","dependencies_parsed_at":"2025-05-12T07:28:39.214Z","dependency_job_id":"ce9f18ef-788f-4c07-ae0d-60b35ed53eed","html_url":"https://github.com/openbakery/OBInjector","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/openbakery/OBInjector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openbakery%2FOBInjector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openbakery%2FOBInjector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openbakery%2FOBInjector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openbakery%2FOBInjector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openbakery","download_url":"https://codeload.github.com/openbakery/OBInjector/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openbakery%2FOBInjector/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280094904,"owners_count":26271003,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-20T02:00:06.978Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-20T12:58:55.442Z","updated_at":"2025-10-20T12:58:56.765Z","avatar_url":"https://github.com/openbakery.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/openbakery/OBInjector.svg?branch=master)](https://travis-ci.org/openbakery/OBInjector)\n\n# OBInjector\n\nThe OBInjector is a very small and simple dependency injector for Objective-C that does property injection.\n\n\n## Usage\n\nSee also the Demo project for details.\n\n### Include into your project \n\nTo use the OBInjector in your project the simples way is to use CocoaPods\n\nAdd the following line to you Podspec:\n\n\n```\npod 'OBInjector', '~\u003e 1.6'\n```\n\nUse the following import in your code:\n\n\n```\n#import \u003cOBInjector/OBInjector.h\u003e\n```\n\n### Set up the injector\n\nNow add the OBInjector instance to your AppDelegate.\n\n```\n\n@implementation AppDelegate {\n}\n\n\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n\t[OBInjectorController configureInjector:^(OBPropertyInjector *injector) {\n\t\tMyService *myService = [[MyService alloc] init];\n\t\t[injector registerProperty:@\"myService\" withInstance:myService];\n\t}];\n}\n\n```\n\n### Use the injector\n\nThe injector is now ready and we want to inject the MyService instance into our ViewController. For this we need to specify the property in the ViewController class:\n\n\n```\n@property(nonatomic, strong) MyService *myService;\n```\n\nIf this property is in the public header or in a private category does't matter.\n\nThe last thing is to tell the injector that it should inject the dependencies to the ViewController. The pattern for this is that always the creater of an instance is responsible for triggering the injector.\nIn this case the ViewController is the root view controller, therefor the AppDelegate is responsible for tiggering the injection, so we add the following code to the `- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {` method:\n\n```\t\n[OBInjectorController injectDependenciesTo:self.window.rootViewController];\t\n```\n\n\nIf the ViewController now creates another view controller, or there is a segue in the storyboard that displays a child view controller, the ViewController is now responsible to trigger the injection to the new view controller.\n\nTo make this simple there is a category on NSObject that helps here:\n\n```\n- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {\n\t[OBInjectorController injectDependenciesTo:segue.destinationViewController];\n}\n```\n\n\n### How it works\n\nWhen the injector is triggered to inject properties to a given class, all properties of the given class are checked if it matches a registered property. \nMatches mean that the property name must be equal to the registered property name, and also the class of the property must match.\n\nThe injector is configured like this:\n\n```\n[OBInjectorController configureInjector:^(OBPropertyInjector *injector) {\n\t\tMyService *myService = [[MyService alloc] init];\n\t\t[injector registerProperty:@“myService” withInstance:myService];\n\t}];\n```\n\nIt is made sure that the configureInjector is only called once.\n\nNow you need to have a class with a property with the name 'myService' of the type 'MyService' so that the instance can be injected:\n\n\n[OBInjectorController injectDependenciesTo:myInstance]\n\n```\n@property(nonatomic, strong) MyService *myService;\n```\n\nThis does __NOT__ work:\n```\n@property(nonatomic, strong) MyService *service;\n```\n\n\n#### Subclasses\n\nThe class type of the injected property must not be exactly the same class. It can be a subclass:\n\n```\nMyExtendedService *myService = [[MyExtendedService alloc] init]; // is subclass of MyService\n[injector registerProperty:@\"myService\" withInstance:MyExtendedService]; \n```\n\n\n#### Protocol\n\nAlso a protocol can be registered for injection:\n\n```\n@protocol FooService \u003cNSObject\u003e\n...\n@end\n```\n```\n@interface FooServiceImpl : NSObject \u003cFooService\u003e\n...\n@end\n```\n\n```\nFooServiceImpl *fooService = [[FooServiceImpl alloc] init];\n[injector registerProperty:@\"fooService\" withInstance:fooService]; \n```\n\n\nIf you now specify following property the FooServiceImpl gets injected:\n\n```\n@protocol (nonatomic, strong) NSObject\u003cFooService\u003e fooService;\n```\n\n\n### Only properties are injected when they are nil\n\n\n```\nviewController.myService = [[MySpecialService alloc] init];\n[injector injectDependenciesTo:viewController];\n```\n\nHere the propery myServices is not changed!!!\n\n\n### How do I know that the properties was injected.\n\nIf your class implements the protocol `OBInjectorDelegate` and the method `- (void)didInjectDependencies;` then this method is called if the injection is finished, but only if something was injected.\n\nYou can use this to finish the initialization for you instance when you need the injected dependencies for this.\n\n### I want to inject always a new instance\n\n\nFor this you can register a property that calls a block that can create the instance:\n\n```\n[injector registerProperty:@\"currentDate\" withBlock:^{\n\treturn [NSDate date];\n}];\n```\n\nIf you now have a property `@property(nonatomic, strong) NSDate *currentDate;` you will always have new NSDate instance set when the property is injected.\n\n## Api Documenation\n\nHere you find the Api documentation generated by AppleDoc:\n\n[http://openbakery.org/documentation/OBInjector/index.html](http://openbakery.org/documentation/OBInjector/index.html)\n\n## Build and test\n\nTo build the project run './gradlew xcodebuild' and to run the unit tests './gradlew test'. You need to have Java installed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenbakery%2Fobinjector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenbakery%2Fobinjector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenbakery%2Fobinjector/lists"}