{"id":18463916,"url":"https://github.com/badchoice/rvcontainer","last_synced_at":"2025-04-28T13:36:52.872Z","repository":{"id":62452262,"uuid":"91601555","full_name":"BadChoice/RVContainer","owner":"BadChoice","description":"Simple lightweight IoC container for objective-c based on Laravel's ","archived":false,"fork":false,"pushed_at":"2020-08-25T10:47:14.000Z","size":32,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-25T07:50:23.602Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/BadChoice.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}},"created_at":"2017-05-17T17:13:32.000Z","updated_at":"2020-08-25T10:47:05.000Z","dependencies_parsed_at":"2022-11-01T23:45:41.673Z","dependency_job_id":null,"html_url":"https://github.com/BadChoice/RVContainer","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BadChoice%2FRVContainer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BadChoice%2FRVContainer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BadChoice%2FRVContainer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BadChoice%2FRVContainer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BadChoice","download_url":"https://codeload.github.com/BadChoice/RVContainer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239162437,"owners_count":19592341,"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-11-06T09:08:21.938Z","updated_at":"2025-02-16T16:52:22.582Z","avatar_url":"https://github.com/BadChoice.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RVContainer\n\nThis is a simple and lightweigh IoC Container for Objective-c based on Laravel's one.\n\n#### Installation\n\n```\npod 'RVContainer'\n```\n\n#### Usage\n\nThere are two options to use it, creating a new `RVContainer` instance and storing it wherever you can access from any part you could need it, or using the singleton provided.\n\nWhen using the singleton there are two ways to use it\n\n```\n[RVContainer container]\n````\n\nor simply using `IOC` marco that shortens the above call.\n\n```\nIOC\n```\n\nTo bind your classes to the container there are several methods\n\n\n##### Basic binding\n```\n[IOC bind:AwesomeClass.class resolver:SubAwesomeClass.class];\n````\n\n```\n[IOC bind:AwesomeClass.class closure: ^(id){\n    return [SubAwesomeClass new];\n}];\n```\n\nYou can bind an instance, so the container will allways return it when asking for that class\n\n``` \nSubAwesomeClass * instance = [SubAwesomeClass new];\n[IOC instance:AwesomeClass.class object:instance];\n```\n\nAnd similar to the previous one, you can register a singleton that will always be returned when asking for it\n```\n[IOC singleton:AwesomeClass.class closure:^id{\n    return [SubAwesomeClass new];\n}];\n````\n\nAnother imporant feature is to bind contracts (or protocols in objective-c).\n\n```\n[IOC bindProtocol:@protocol(aProtocol) resolver:ClassThatImplementsTheProtocol.class];\n````\n\n#### Resolve\nIf you try to resolve a class not in the container, it will return a new instance of the class requested\n\n```\nAwesomeClass * object  = [IOC make:SubAwesomeClass.class];\n```\n\n```\nClassThatImplementsTheProtocol * object  = [IOC makeProtocol:@protocol(aProtocol)];\n``` \n\n### Autoinject\nIf you don't want to clutter your classes with container resolving things you can use autoinject\nIt will automatically inject the dependencies to you object properties\n\nYou need to declare the properties to be injected like the following:\n\n```\n#import \"RVAutoInject.h\"\n\n@interface ClassWithObjectsToBeInjected : NSObject\n\n@property(strong,nonatomic) inject(AwesomeClass) *subtest;\n@property(strong,nonatomic) TestClass *test;\n@property(strong,nonatomic) injectProtocol(aProtocol) *testProtocol;\n\n@end\n```\n\nAnd then in your init method call\n\n```\n[RVAutoInject autoInject:self];\n```\n\n\u003e I'm not really happy with this Autoinject call but I don't know how to make it automatically\n\n### Contributing\nI really welcome any issue and PR so feel free to post them\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadchoice%2Frvcontainer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbadchoice%2Frvcontainer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadchoice%2Frvcontainer/lists"}