{"id":19034154,"url":"https://github.com/aurasphere/revolver-compiler","last_synced_at":"2025-10-11T11:12:04.826Z","repository":{"id":55385871,"uuid":"68398214","full_name":"aurasphere/revolver-compiler","owner":"aurasphere","description":"Compiler for the Revolver Dependency Injection framework.","archived":false,"fork":false,"pushed_at":"2021-01-04T07:28:24.000Z","size":159,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-02T04:48:27.273Z","etag":null,"topics":["annotation-processor","compile-time-dependency-injection","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aurasphere.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":"2016-09-16T16:57:35.000Z","updated_at":"2021-01-04T07:28:26.000Z","dependencies_parsed_at":"2022-08-14T23:10:20.272Z","dependency_job_id":null,"html_url":"https://github.com/aurasphere/revolver-compiler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aurasphere%2Frevolver-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aurasphere%2Frevolver-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aurasphere%2Frevolver-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aurasphere%2Frevolver-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aurasphere","download_url":"https://codeload.github.com/aurasphere/revolver-compiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240088325,"owners_count":19746076,"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":["annotation-processor","compile-time-dependency-injection","dependency-injection","java"],"created_at":"2024-11-08T21:43:39.904Z","updated_at":"2025-10-11T11:11:59.784Z","avatar_url":"https://github.com/aurasphere.png","language":"Java","funding_links":["https://www.paypal.com/donate/?cmd=_donations\u0026business=8UK2BZP2K8NSS"],"categories":[],"sub_categories":[],"readme":"[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/aurasphere/revolver-compiler/blob/master/LICENSE)\n[![Donate](https://img.shields.io/badge/Donate-PayPal-orange.svg)](https://www.paypal.com/donate/?cmd=_donations\u0026business=8UK2BZP2K8NSS)\n\n# Revolver\n\n## Overview\nA simple compile-time dependency injection framework. Revolver works with [standard javax.inject annotations](https://docs.oracle.com/javaee/7/api/javax/inject/package-summary.html).\n\n## Usage\nBefore using this project in production, read the [known issues section](#known-issues).\n\n### Maven Configuration\nAfter building Revolver locally, you can add it to your project pom.xml like this:\n\n    \u003cbuild\u003e\n        \u003cplugins\u003e\n            \u003cplugin\u003e\n                \u003cgroupId\u003eorg.apache.maven.plugins\u003c/groupId\u003e\n                \u003cartifactId\u003emaven-compiler-plugin\u003c/artifactId\u003e\n                \u003cversion\u003e3.6.1\u003c/version\u003e\n                \u003cconfiguration\u003e\n                    \u003cannotationProcessorPaths\u003e\n                        \u003cpath\u003e\n                            \u003cgroupId\u003eco.aurasphere.revolver\u003c/groupId\u003e\n                            \u003cartifactId\u003erevolver-compiler\u003c/artifactId\u003e\n                            \u003cversion\u003e1.0.1\u003c/version\u003e\n                        \u003c/path\u003e\n                    \u003c/annotationProcessorPaths\u003e\n                \u003c/configuration\u003e\n            \u003c/plugin\u003e\n        \u003c/plugins\u003e\n    \u003c/build\u003e\n\n### Quickstart\n\nTo register a component under Revolver context, you use the `javax.inject.Singleton` annotation:\n\n    @Singleton\n    public class MyComponent {\n        ...\n    }\n    \nComponent injection is performed by using the `javax.inject.Inject` annotation and invoking the `Revolver.inject` method by passing the object to inject (usually done in the constructor):\n\n\n    public class MyMainClass {\n   \n        @Inject\n        public MyComponent injectedComponent;\n       \n        public MyMainClass() {\n            Revolver.inject(this);\n        }\n    }\n\nThe Revolver class is auto-generated during compilation, so you need to run a build (which will fail the first time for this reason) before you can use it. If using Maven, the generated files will be found under `target/generated-sources/annotations`, so you may want to add that directory to your IDE source configuration to simplify your setup. And that's it!\n\n### Injection Types\nRevolver supports 3 types of injection: field injection, setter injection and constructor injection.\n\n#### Field Injection\nTo perform field injection, simply add `@Inject` to the field you want to inject:\n\n    public class MyClass {\n           \n        @Inject\n        public MyComponent injectedComponent;\n           \n        public MyClass() {\n            Revolver.inject(this);\n        }\n    }\n\n#### Setter Injection\nSetter injection will be automatically performed if the annotated field is not private. In this case, Revolver will look for a public setter named following the standard JavaBeans convention with only one argument of the same type of the field:\n\n    public class MyClass {\n           \n        @Inject\n        private MyComponent injectedComponent;\n           \n        public MyClass() {\n            Revolver.inject(this);\n        }\n           \n        // This method will be called.\n        public void setInjectedComponent(MyComponent injectedComponent) {\n            this.injectedComponent = injectedComponent;\n        }   \n    }\n\n#### Constructor Injection\nConstructor injection will be performed if any registered component specifies arguments in its constructor:\n\n    @Singleton\n    public class MyComponentOne {\n    }\n    \n    @Singleton\n    public class MyComponentTwo {\n   \n        public MyComponentOne myComponentOne;\n       \n        public MyComponentTwo(MyComponentOne myComponentOne) {\n            this.myComponentOne = myComponentOne;\n        }\n   \n    }\n    \n    public class MyMainClass {\n   \n        // This field will contain an injected component one!\n        @Inject\n        public MyComponentTwo myComponentTwo;\n       \n        public MyMainClass() {\n            Revolver.inject(this);\n        }\n   \n    }\n\nIf your component has more than one constructor, you can choose which one will be called by annotating it with `@Inject`:\n\n    @Singleton\n    public class MyComponentTwo {\n   \n        public MyComponentOne myComponentOne;\n        \n        public MyComponentTwo() {}\n       \n        // This is the constructor that will be called by Revolver\n        @Inject\n        public MyComponentTwo(MyComponentOne myComponentOne) {\n            this.myComponentOne = myComponentOne;\n        }\n    }\n\n### Collection Injection\nIf you have multiple components implementing/extending one common superclass, you can inject all of them inside a `Collection`(`List`, `Set`, `Map`, `Queue`) or an `Array`:\n\n    public class MyClass {\n           \n        // Will contain all the registered components that implements Runnable.\n        @Inject\n        public List\u003cRunnable\u003e tasksToExecute;\n           \n        public MyClass() {\n            Revolver.inject(this);\n        }\n    }\n\n### Programmatic Components\nSometimes, you need to register components from classes that are not under your control (for example, 3rd-party libraries). In this case, you can create a method that returns the component and annotate both the class and the method with `@Singleton`.\nThe method can have as many arguments as you want, and they will be automatically injected:\n\n    @Singleton\n    public class MyComponentProvider {\n   \n        // The parameter will be provided by Revolver if it's a registered component\n        @Singleton\n        public Retrofit createRetrofit(String myApiUrl) {\n           return new Retrofit.Builder().baseUrl(myApiUrl).build();\n        }\n    }\n\nNotice that like all other components managed by Revolver, anything produced by your method will be a `Singleton`, meaning that only one instance is produced. In this example, each time you require a `Retrofit` component for injection, the same component will be injected. The defined method will be thus called only once.\n\nWhen you start creating components this way, it's easy to generate ambiguities in types. In this case, you give the produced component an identifier using the `javax.inject.Named` annotation:\n\n    @Singleton\n    public class MyComponentProvider {\n   \n        @Named(\"apiUrl\")\n        @Singleton\n        public String createApiUrl() {\n            return \"https://github.com\";\n        }\n        \n        @Named(\"helloMessage\")\n        @Singleton\n        public String createHelloWorldMessage() {\n            return \"Hello World\";\n        }\n    }\n    \n    public class MainClass {\n    \n        @Named(\"helloMessage\")\n        public String msg;\n   \n        public MainClass() {\n            Revolver.inject(this);\n            // Prints Hello World\n            System.out.println(msg);\n        }\n    }\n\n## Known Issues\nSince this project was mostly an experiment, it's adviced not to use it in any serious application. Known issues are the following:\n - Insufficient test coverage (tested only with Maven)\n - Impossibility to override components. When testing, you can mock the static inject method with a 3rd party library like Mockito\n - Components produced during the `compile` phase cannot be injected inside components produced during the `testCompile` phase, making unit testing extremely difficult\n - Not available on Maven Central, so you will have to build the project locally\n \n## Contributions\nIf you want to contribute on this project, just fork this repo and submit a pull request with your changes. Improvements are always appreciated! I'm also looking for mainteners that want to continue improving this concept.\n\n## Project status\nThis project is considered completed and won't be developed further unless I get any specific requests (which I may consider).\n\n## Contacts\nYou can contact me using my account e-mail or opening an issue on this repo. I'll try to reply back ASAP.\n\n## License and purpose of the project\nThe project is released under the MIT license, which lets you reuse the code for any purpose you want (even commercial) with the only requirement being copying this \u003ca href=\"LICENSE\"\u003eproject license\u003c/a\u003e on your project.\n\n\u003csub\u003eCopyright (c) 2016-2021 Donato Rimenti\u003c/sub\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faurasphere%2Frevolver-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faurasphere%2Frevolver-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faurasphere%2Frevolver-compiler/lists"}