{"id":19059561,"url":"https://github.com/vaibhavpandeyvpz/katora-java","last_synced_at":"2026-06-19T03:31:34.774Z","repository":{"id":84581378,"uuid":"238628589","full_name":"vaibhavpandeyvpz/katora-java","owner":"vaibhavpandeyvpz","description":"Simple service container for Java (and Android) apps.","archived":false,"fork":false,"pushed_at":"2020-02-09T03:57:44.000Z","size":111,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-22T01:43:52.053Z","etag":null,"topics":["container","di","ioc","java","service","singleton"],"latest_commit_sha":null,"homepage":"https://github.com/vaibhavpandeyvpz/katora-java","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/vaibhavpandeyvpz.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":"2020-02-06T07:09:20.000Z","updated_at":"2022-04-08T23:13:39.000Z","dependencies_parsed_at":"2024-02-11T06:15:14.425Z","dependency_job_id":null,"html_url":"https://github.com/vaibhavpandeyvpz/katora-java","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/vaibhavpandeyvpz/katora-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaibhavpandeyvpz%2Fkatora-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaibhavpandeyvpz%2Fkatora-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaibhavpandeyvpz%2Fkatora-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaibhavpandeyvpz%2Fkatora-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vaibhavpandeyvpz","download_url":"https://codeload.github.com/vaibhavpandeyvpz/katora-java/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaibhavpandeyvpz%2Fkatora-java/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34516549,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"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":["container","di","ioc","java","service","singleton"],"created_at":"2024-11-09T00:10:35.708Z","updated_at":"2026-06-19T03:31:34.750Z","avatar_url":"https://github.com/vaibhavpandeyvpz.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# katora-java\nSimple service container for Java apps.\n\n[![Build](https://img.shields.io/github/workflow/status/vaibhavpandeyvpz/katora-java/Java%20CI?style=flat-square)](https://github.com/vaibhavpandeyvpz/katora-java/actions)\n[![Release](https://jitpack.io/v/vaibhavpandeyvpz/katora-java.svg)](https://jitpack.io/#vaibhavpandeyvpz/katora-java)\n\nThis project aims to solve the code organisation problem with the infamous [Singleton](https://www.baeldung.com/java-singleton) pattern (and factories) common among Java (and maybe other languages as well) developers.\nInstead of hidden singletons throughout your project's codebase, they can now be registered at a single place and be accessed throughout.\n\nFor even better project structure, I recommend implementing service `Provider` interface and registering services therein.\n\n## Installation\n\nThe package is built and tested using [Github Actions](https://github.com/features/actions) but installation is facilitated via [JitPack](https://jitpack.io/) for ease.\nThe steps to include [Katora](https://github.com/vaibhavpandeyvpz/katora-java) are as follows:\n\nIn your project's `build.gradle` file, include below repository:\n\n```groovy\nrepositories {\n\n    // ... other repositories\n\n    maven { url 'https://jitpack.io' }\n}\n\ndependencies {\n\n    // ... other dependencies\n\n    implementation 'com.github.vaibhavpandeyvpz:katora-java:1.0.0'\n}\n```\n\n## Usage\n\nThis library can be used in several ways. I have just document the most common ones below.\n\n### Barebones\n\nFirst approach in create just one Container singleton (instead of many) and register desired services with the container.\nLet's suppose you have a service class `YourService` that depends on an object of `YourServiceDependency` class.\nIt can be defined as follows:\n\n```java\nimport com.vaibhavpandey.katora.Container;\n\npublic class YourSingleton {\n\n    private static Container mContainer;\n\n    public static void createContainer() {\n        Container container = new Container();\n        container.factory(YourServiceDependency.class, c -\u003e new YourServiceDependency());\n        container.singleton(YourService.class, c -\u003e new YourService(c.get(YourServiceDependency.class)));\n        container.factory(\"youralias\", c -\u003e c.get(YourService.class));\n        mContainer = container;\n    }\n\n    public static Container getContainer() {\n        return mContainer;\n    }\n}\n```\n\nThen later, you first create the container (just once) and then fetch the service anywhere in your app from your container using:\n\n```java\npublic class YourMainClass {\n\n    public static void main(String[] args) {\n        // call this just once ...\n        YourSingleton.createContainer();\n        // ... and then use it here or anywhere e.g.,\n        YourService service = YourSingleton.getContainer().get(YourService.class); // or \"youralias\" instead of Class name\n    }\n}\n```\n\n### Providers\n\nRecommended approach is to organise services into `Provider`s, install them onto your container and delegate service registrations as shown below.\n\nHere is our provider #1 that actually registers the services.\n\n```java\nimport com.vaibhavpandey.katora.contracts.Provider;\n\npublic class YourServiceProvider implements Provider {\n\n    @Override\n    public void provide(MutableContainer container) {\n        container.factory(YourServiceDependency.class, c -\u003e new YourServiceDependency());\n        container.singleton(YourService.class, c -\u003e new YourService(c.get(YourServiceDependency.class)));\n    }\n}\n```\n\nHere is our provider #2 that just registers string alias to registered services.\n\n```java\nimport com.vaibhavpandey.katora.contracts.Provider;\n\npublic class YourAliasProvider implements Provider {\n\n    @Override\n    public void provide(MutableContainer container) {\n        container.factory(\"youralias\", c -\u003e c.get(YourService.class));\n    }\n}\n```\n\nThen composing your container using above providers like:\n\n```java\nimport com.vaibhavpandey.katora.Container;\n\npublic class YourSingleton {\n\n    private static Container mContainer;\n\n    public static void createContainer() {\n        mContainer = new Container()\n            .install(new YourServiceProvider())\n            .install(new YourAliasProvider());\n    }\n\n    public static Container getContainer() {\n        return mContainer;\n    }\n}\n```\n\nSo that's how all of the above organises your project's code base while not enforcing any new coding pattern than Singleton.\nI created this library to stop repeating myself among projects and maybe product more maintainable code.\n\n### License\nSee [LICENSE](LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaibhavpandeyvpz%2Fkatora-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvaibhavpandeyvpz%2Fkatora-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaibhavpandeyvpz%2Fkatora-java/lists"}