{"id":3212,"url":"https://github.com/appfoundry/Reliant","last_synced_at":"2025-08-03T13:32:14.379Z","repository":{"id":3324678,"uuid":"4367966","full_name":"appfoundry/Reliant","owner":"appfoundry","description":"Nonintrusive Objective-C Dependency Injection","archived":false,"fork":false,"pushed_at":"2016-06-29T14:19:33.000Z","size":850,"stargazers_count":51,"open_issues_count":4,"forks_count":6,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-04-29T19:04:54.239Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/appfoundry.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-05-18T10:05:04.000Z","updated_at":"2023-12-15T09:46:20.000Z","dependencies_parsed_at":"2022-08-28T01:02:40.694Z","dependency_job_id":null,"html_url":"https://github.com/appfoundry/Reliant","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appfoundry%2FReliant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appfoundry%2FReliant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appfoundry%2FReliant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appfoundry%2FReliant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/appfoundry","download_url":"https://codeload.github.com/appfoundry/Reliant/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228548567,"owners_count":17935221,"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","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":"2024-01-05T20:16:34.627Z","updated_at":"2024-12-07T01:30:42.736Z","avatar_url":"https://github.com/appfoundry.png","language":"Objective-C","funding_links":[],"categories":["Dependency Injection","Injection","WebSocket"],"sub_categories":["Getting Started","Other free courses","Web View"],"readme":"Reliant\n=======\n[//]: # (remove-section start)\n\n[![Reliant build status](https://img.shields.io/travis/appfoundry/Reliant/master.svg)](https://travis-ci.org/appfoundry/reliant)   [![Cocoapods Version](https://img.shields.io/cocoapods/v/Reliant.svg)](http://cocoadocs.org/docsets/Reliant/2.0.1/)\n\n[//]: # (remove-section end)\n\nReliant is a Dependency Injection ([DI](http://martinfowler.com/articles/injection.html \"Martin Fowler never lies\"))\nframework for Objective-C, both for OS X and iOS. Its goal is to make its use as simple\nas possible, while not limiting possibilities. It aims to have as little impact as\npossible on your project code. It also aims to be loyal to Objective-C's [dynamic](http://stackoverflow.com/questions/125367/dynamic-type-languages-versus-static-type-languages)\nnature.\n\n\nGetting started\n---------------\n\nIn this section we will get you started with Reliant as quick as possible, if you want to know more\n(or in other words, the TL;DR version) we suggest you take a look at our [wiki pages](https://github.com/appfoundry/Reliant/wiki)\n\n### Installation\n\nThe easiest way to install Reliant is via CocoaPods\n\nAdd the following line to your Podfile:\n\n`pod 'Reliant'`\n\nThen run `pod install` or `pod update`\n\n\u003e for more information about CocoaPods, go to http://cocoapods.org\n\n### Quick-start tutorial\n\nWe suggest that you first take a look at our [quick-start 'Hello World' tutorial](https://github.com/appfoundry/Reliant/tree/master/Examples/HelloReliant) and sample app, found under the [Examples](https://github.com/appfoundry/Reliant/tree/master/Examples) folder in the Reliant repository.\n\n\nUsing Reliant\n-------------\n\nThe following documentation is based on our more elaborate [sample app](https://github.com/appfoundry/Reliant/tree/master/Examples/ReliantExample), which can also be found under the [Examples](https://github.com/appfoundry/Reliant/tree/master/Examples) folder in the Reliant repository.\n\n#### Configuration\n\nYou first need a context in which Reliant will look for your specific objects. The default way to configure such a\ncontext is through a configuration class. The example contains some of these. The application wide context is configured\nwith the `AppConfiguration` class.\n\n```objective-c\n//Header file omitted\n\n@implementation AppConfiguration\n\n- (id\u003cStringProvider\u003e)createSingletonStringProvider {\n    return [[DefaultStringProvider alloc] init];\n}\n\n@end\n```\n\nIn this very simple example we have the concept of a `StringProvider` which will generate some strings shown by various\nviews in our application. We configure Reliant to create a \"singleton\" instance of this string provider. The reason why\nyou would use dependency injection is that you can avoid hard dependencies to implementations. That's why we have\na `StringProvider` protocol. The configuration will create an actual implementation instance, but that instance is hidden\nfrom the actual dependent application code. In this case we use the `DefaultStringProvider`.\n\n#### Bootstrapping a context\n\nBootstrapping a context is very simple. Since we have a configuration for a context which is meant to be used\nthroughout the entire application, we will bootstrap this context in the application delegate.\n\n```objective-c\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n    [self ocsBootstrapAndBindObjectContextWithConfiguratorFromClass:[AppConfiguration class]];\n}\n```\n\nThis single line of code is the easiest way to bootstrap a context. It wil start the context with the specified\nconfiguration class, and then bind that context to `self` which in this case means your application delegate.\n\n#### Injection\n\nReliant injects all your objects specified in the configuration. Injection can be done in two ways:\n- Initializer injection\n- Property injection\n\nFor simplicity's sake we will use property injection in these examples.\n\n\u003e We actually prefer initializer injection over property injection, but we will get into that in our [wiki pages](https://github.com/appfoundry/Reliant/wiki).\n\nLet's say that our `DefaultStringProvider` implementation needs a `StringGenerator` to generate some strings.\nWe could do this by simply adding a property named `stringGenerator` on our `DefaultStringProvider`.\n\n```objective-c\n@interface DefaultStringProvider : NSObject\u003cStringProvider\u003e\n\n@property (nonatomic, strong) id\u003cStringGenerator\u003e stringGenerator;\n\n@end\n```\n\nNow we just need to add another configuration method to our `AppConfiguration` class.\n\n```objective-c\n//Inside the implementation of our AppConfiguration\n\n- (id\u003cStringGenerator\u003e)createSingletonStringGenerator {\n    return [[DefaultStringGenerator alloc] init];\n}\n```\n\nWith that, when you start your application, both the `DefaultStringProvider` and `DefaultStringGenerator` are being\ncreated for the AppDelegate's context. Remember when we said they were created as \"singletons\"? Well, they are not real\nsingletons, but they are in the `AppDelegate` context. When you ask the context for this object, it will always return\nthe same instance, guaranteed.\n\n\u003e For those of you who prefer to put the property in an anonymous class extension, as we do, that would work as well.\n\nAfter the creation of an object, it will be injected with other objects known by the context it is created for. So in this\ncase the `DefaultStringGenerator` is injected in the `DefaultStringProvider` through its `stringGenerator` property.\n\nYou easily succeeded in loosly coupling the `StringGenerator` to your `DefaultStringProvider` class.\n\n#### Manual injection\n\nIt might not always be possible to configure your objects through Reliant. For instance, a view controller might get created\nby a storyboard or by your applications code somewhere. In these cases Reliant will not be able to inject your object\nautomatically. However, injecting an object is a one-liner again:\n\n```objective-c\n[self ocsInject];\n```\n\nThis will locate a context based on `self`, and then inject `self`with objects known to the found context.\n\n#### Naming your objects\n\nReliant figures out which objects to inject by their given name. In this case, the names of our object are `stringProvider`\nand `stringGenerator`. That is why we named the property in `DefaultStringProvider` as such. The names of the objects are\nspecified by your configurator. In this case Reliant derives the name from the method names. All text which comes after the\n`createSingleton` is seen as a name. The tentative reader might argue that the names should be *StringGenerator* and\n*StringProvider* (with starting capital), in fact that is true. However, Reliant has created aliases for these objects\nin their camelcase form.\n\nFurther reading\n---------------\n\nDo not forget to check our [wiki pages](https://github.com/appfoundry/Reliant/wiki) for more details on what is discussed above.\nOur API documentation is available via [cocoadocs.org](http://cocoadocs.org/docsets/Reliant)\n\nContact\n-------\nIf not via GitHub, find us on twitter: @AppFoundryBE or @mikeseghers\n\nLicence\n-------\n\nReliant is released under [MIT licence](http://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappfoundry%2FReliant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fappfoundry%2FReliant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappfoundry%2FReliant/lists"}