{"id":19623468,"url":"https://github.com/jbock-java/simple-component","last_synced_at":"2026-02-07T08:32:49.044Z","repository":{"id":65589204,"uuid":"587879516","full_name":"jbock-java/simple-component","owner":"jbock-java","description":"Basic dependency injection tool","archived":false,"fork":false,"pushed_at":"2024-10-25T05:03:03.000Z","size":708,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-28T04:34:50.204Z","etag":null,"topics":["annotation-processor","dagger","dependency-injection","java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jbock-java.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-11T19:59:40.000Z","updated_at":"2024-10-25T05:03:06.000Z","dependencies_parsed_at":"2024-01-09T16:45:14.173Z","dependency_job_id":"1ac6f05f-7113-4bbc-ae98-87cfce3ada9c","html_url":"https://github.com/jbock-java/simple-component","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/jbock-java/simple-component","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbock-java%2Fsimple-component","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbock-java%2Fsimple-component/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbock-java%2Fsimple-component/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbock-java%2Fsimple-component/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jbock-java","download_url":"https://codeload.github.com/jbock-java/simple-component/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbock-java%2Fsimple-component/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29190215,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T07:37:03.739Z","status":"ssl_error","status_checked_at":"2026-02-07T07:37:03.029Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["annotation-processor","dagger","dependency-injection","java"],"created_at":"2024-11-11T11:34:04.981Z","updated_at":"2026-02-07T08:32:49.028Z","avatar_url":"https://github.com/jbock-java.png","language":"Java","readme":"[![simple-component-compiler](https://maven-badges.herokuapp.com/maven-central/io.github.jbock-java/simple-component-compiler/badge.svg?color=grey\u0026subject=simple-component-compiler)](https://maven-badges.herokuapp.com/maven-central/io.github.jbock-java/simple-component-compiler)\n[![simple-component](https://maven-badges.herokuapp.com/maven-central/io.github.jbock-java/simple-component/badge.svg?subject=simple-component)](https://maven-badges.herokuapp.com/maven-central/io.github.jbock-java/simple-component)\n\ntl;dr minimal example:\n\n```java\nclass CoffeeApp {\n\n    @Component interface CoffeeComponent {\n        CoffeeMaker coffeeMaker();\n\n        @Component.Builder interface Builder {\n            Builder logLevel(String logLevel);\n            CoffeeComponent buildComponent();\n        }\n    }\n\n    interface Logger {\n        void log(String msg);\n    }\n\n    static class CoffeeMaker {\n        private final Logger logger;\n\n        @Inject CoffeeMaker(Logger logger) {\n            this.logger = logger;\n        }\n\n        void brew() {\n            logger.log(\"~ ~ ~ heating ~ ~ ~\");\n            logger.log(\"=\u003e =\u003e pumping =\u003e =\u003e\");\n            logger.log(\" [_]P coffee! [_]P \");\n        }\n    }\n\n    @Inject static Logger createLogger(String level) {\n        return msg -\u003e System.out.println(level + \" \" + msg);\n    }\n}\n```\n\nThis dependency injector uses the following annotations:\n1. `@Inject` declares an injection point. It can be a constructor or a static method in the bean class. It can also be a static method in the component class.\n2. `@Qualifier` and its default implementation `@Named`.\n3. And of course, `@Component`, `@Component.Factory` and `@Component.Builder`.\n\nNote this is not a complete implementation of `javax.inject` or `jakarta.inject`, because:\n\n### The `@Scope` and `@Singleton` annotations are ignored.\n\nInstead there's the following rule:\n\n\u003e If two beans of the *same type* and *same qualifier* are injected by the *same component*, then they are the *same instance*.\n\nIntuitively this means the same bean instance is injected everywhere (unless you're using qualifiers, or inject a provider). So everything is a \"singleton\".\nIn the example above, if multiple beans would request the logger, they would all get the same logger instance.\n\nIf you want to re-use a bean instance across multiple components, or multiple instances of the same component, use a `@Factory` or a `@Builder` to pass it around.\nComponents will prefer using an existing bean instance over creating a new one.\n\nIf you inject `Provider\u003cTheBean\u003e`, rather than `TheBean` directly, calling `provider.get()` will create a fresh bean instance every time.\n\n### Mocking\n\nIf you want create a component where some beans are swapped for mock instances, use `@Component(mockBuilder = true)`.\nA static `mockBuilder` method will be generated, which returns a MockBuilder that can be used to register your mocks.\n(If your component uses `@Component.Builder`, the generated builder will have a `withMocks` method that returns the MockBuilder.)\n[Usage example](https://github.com/jbock-java/modular-thermosiphon):\n\n```java\nList\u003cString\u003e messages = new ArrayList\u003c\u003e();\nCoffeeApp.Logger mockLogger = messages::add;\nCoffeeApp.CoffeeComponent app = CoffeeApp_CoffeeComponent_Impl.builder()\n        .logLevel(\"\")\n        .withMocks()\n        .coffeeAppLogger(mockLogger)\n        .build();\napp.coffeeMaker().brew();\nassertEquals(List.of(\n                \"~ ~ ~ heating ~ ~ ~\",\n                \"=\u003e =\u003e pumping =\u003e =\u003e\",\n                \" [_]P coffee! [_]P \"),\n        messages);\n```\n\n### Note to dagger users\n\nThere are no \"subcomponents\" or \"component dependencies\".\n\nThere is no `@Module`, but you can still have `@Provides` methods, only you declare them directly in your component.\nA `@Provides` method must be `static`.\n\nThere is no `@Binds`.\nIt can be emulated with a `@Provides` method, or, if you control the source code of the interface, a static `@Inject` method.\n\nThere is no need for the `@BindsInstance` annotation. Every factory parameter or builder parameter is a bound instance.\n\nThere is no `@AssistedInject`, it's a can of worms.\n\nThere is no `@IntoList` or `@IntoSet`, you can return these collections from a `@Provides` method.\n\nThere is no `Lazy\u003cT\u003e`, please check if `Provider\u003cT\u003e` covers your use case.\n\n### Samples\n\n* [modular-thermosiphon (dagger's \"coffee machine\" demo)](https://github.com/jbock-java/modular-thermosiphon)\n* [jbock](https://github.com/jbock-java/jbock) uses it, see for example [ValidateComponent](https://github.com/jbock-java/jbock/blob/master/compiler/src/main/java/net/jbock/validate/ValidateComponent.java)\n\n### Alternatives\n\n* https://github.com/google/dagger/\n* https://github.com/avaje/avaje-inject\n* https://github.com/michaelboyles/simple-di\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbock-java%2Fsimple-component","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjbock-java%2Fsimple-component","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbock-java%2Fsimple-component/lists"}