{"id":13613617,"url":"https://github.com/rh-id/a-provider","last_synced_at":"2026-05-11T01:05:14.028Z","repository":{"id":40622182,"uuid":"406974032","full_name":"rh-id/a-provider","owner":"rh-id","description":"This is a simple pure java service locator for Android","archived":false,"fork":false,"pushed_at":"2024-12-17T02:19:18.000Z","size":160,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-11T18:30:51.049Z","etag":null,"topics":["android","android-lib","android-library","provider","service-locator"],"latest_commit_sha":null,"homepage":"","language":"Java","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/rh-id.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}},"created_at":"2021-09-16T01:17:47.000Z","updated_at":"2024-12-29T22:32:32.000Z","dependencies_parsed_at":"2024-01-25T02:03:30.822Z","dependency_job_id":"3618bc46-7faa-4832-8f8e-8c242227d13b","html_url":"https://github.com/rh-id/a-provider","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rh-id%2Fa-provider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rh-id%2Fa-provider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rh-id%2Fa-provider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rh-id%2Fa-provider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rh-id","download_url":"https://codeload.github.com/rh-id/a-provider/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241311730,"owners_count":19942227,"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":["android","android-lib","android-library","provider","service-locator"],"created_at":"2024-08-01T20:00:51.745Z","updated_at":"2026-05-11T01:05:13.973Z","avatar_url":"https://github.com/rh-id.png","language":"Java","funding_links":[],"categories":["Android"],"sub_categories":[],"readme":"# a-provider\n\n![JitPack](https://img.shields.io/jitpack/v/github/rh-id/a-provider)\n![Downloads](https://jitpack.io/v/rh-id/a-provider/week.svg)\n![Downloads](https://jitpack.io/v/rh-id/a-provider/month.svg)\n![Android CI](https://github.com/rh-id/a-provider/actions/workflows/gradlew-build.yml/badge.svg)\n\nThis is a simple Service Locator for Android projects that doesn't rely on annotations or \"magic\"\n\n\n## Example Usage\n\nThis project support jitpack, in order to use this, you need to add jitpack to your project root build.gradle:\n```\nallprojects {\n    repositories {\n        google()\n        mavenCentral()\n        maven { url \"https://jitpack.io\" }\n        jcenter() // Warning: this repository is going to shut down soon\n    }\n}\n```\n\nInclude this to your module dependency (module build.gradle)\n```\ndependencies {\n    implementation 'com.github.rh-id:a-provider:v0.0.1'\n}\n```\n\nThen you could proceed writing code,\nFirst create root module as a root of the provider to provide services.\n\n```\npublic class RootModule implements ProviderModule{\n    @Override\n    void provides(ProviderRegistry providerRegistry, Provider provider){\n        // Register your services/components here or other ProviderModule\n        providerRegistry.register(IService.class, () -\u003e new ServiceImpl());\n        providerRegistry.registerModule(new ProviderModuleA());\n        // You could use registerLazy to lazy-load your services\n        providerRegistry.registerLazy(IServiceA.class, ServiceAImpl::new);\n        // You could use registerAsync to initialize your services in background thread\n        providerRegistry.registerAsync(IServiceB.class,\n                                        () -\u003e new ServiceBImpl(provider.get(IServiceA.class)));\n        // use registerFactory to load new instances everytime Provider.get() is invoked\n        providerRegistry.registerFactory(MyPojo.class, () -\u003e {\n            MyPojo myPojo = new MyPojo();\n            myPojo.setAge(99);\n            myPojo.setName(\"Foo\");\n            return myPojo;\n        });\n        // OR use registerPool to load new instances everytime Provider.get() is invoked.\n        providerRegistry.registerPool(MyPojo.class, () -\u003e {\n            MyPojo myPojo = new MyPojo();\n            myPojo.setAge(99);\n            myPojo.setName(\"Foo\");\n            return myPojo;\n        });\n    }\n\n    @Override\n    void dispose(Provider provider){\n        // do something when this module is going to be disposed\n    }\n}\n```\n\nInitialize on your application for global access (example only)\n\n```\npublic class MyApplication extends Application {\n    @Override\n    public void onCreate() {\n        super.onCreate();\n        // store the instance in static value for global access\n        Provider provider = Provider.createProvider(this, new RootModule());\n        // example retrieve value\n        IServiceA iServiceA = provider.get(IServiceA.class);\n        MyPojo myPojo = provider.get(MyPojo.class);\n    }\n}\n```\nIf you need to handle dispose event you could implement `ProviderDisposable` to your component/services\n```\npublic class ServiceAImpl implements IServiceA, ProviderDisposable {\n    @Override\n    public void dispose(Context context){\n    // anything to dispose, this will be called on Provide.dispose\n    }\n}\n```\n```\npublic class MyApplication extends Application {\n    @Override\n    public void onCreate() {\n        super.onCreate();\n        Provider provider = Provider.createProvider(this, new RootModule());\n        IServiceA iServiceA = provider.get(IServiceA.class);\n        provider.dispose(); // ServiceAImpl.dispose(Context) will be called\n    }\n}\n```\n\n## Skipping same type\n\nFor integration testing purposes you could turn on `skipSameType`. This will make `providerRegistry`\nignore duplicate type during registration\n\nExample production RootModule:\n\n```\npublic class RootModule implements ProviderModule{\n    @Override\n    void provides(ProviderRegistry providerRegistry, Provider provider){\n        providerRegistry.register(IService.class, () -\u003e new ServiceImpl());\n    }\n}\n```\n\nExample test RootModule to be used:\n\n```\npublic class TestRootModule extends RootModule{\n    @Override\n    void provides(ProviderRegistry providerRegistry, Provider provider){\n        // register IService.class with test instance\n        providerRegistry.register(IService.class, () -\u003e new TestServiceImpl());\n\n        providerRegistry.setSkipSameType(true); // enable\n        // since skip is true, the IService.class from parent will not be registered again\n        super.provides(providerRegistry, provider); \n        providerRegistry.setSkipSameType(false); // disable skip after done\n    }\n}\n```\n\nThe configuration `providerRegistry.setSkipSameType(true);` can be useful on some circumstances such\nas multiple android app flavors or configuration\n\n## Example Projects\n\n\u003cul\u003e\n\u003cli\u003ehttps://github.com/rh-id/a-news-provider\u003c/li\u003e\n\u003cli\u003ehttps://github.com/rh-id/a-flash-deck\u003c/li\u003e\n\u003cli\u003ehttps://github.com/rh-id/a-medic-log\u003c/li\u003e\n\u003cli\u003ehttps://github.com/rh-id/a-personal-stuff\u003c/li\u003e\n\u003c/ul\u003e\n\n## Support this project\nConsider donation to support this project\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ca href=\"https://trakteer.id/rh-id\"\u003ehttps://trakteer.id/rh-id\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frh-id%2Fa-provider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frh-id%2Fa-provider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frh-id%2Fa-provider/lists"}