{"id":27242762,"url":"https://github.com/zeldan/your-own-dependency-injection-framework","last_synced_at":"2025-04-10T20:22:02.924Z","repository":{"id":217195606,"uuid":"84369496","full_name":"zeldan/your-own-dependency-injection-framework","owner":"zeldan","description":"lightweight dependency injection framework example in java","archived":false,"fork":false,"pushed_at":"2024-06-22T15:55:52.000Z","size":69,"stargazers_count":23,"open_issues_count":0,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-22T23:33:52.989Z","etag":null,"topics":["dependency-injection","dependency-injection-framework","java","java-tutorial","tutorial-code"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zeldan.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":"2017-03-08T21:50:35.000Z","updated_at":"2024-06-22T15:55:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"25926c34-3982-4c8f-bced-f18ca16db602","html_url":"https://github.com/zeldan/your-own-dependency-injection-framework","commit_stats":null,"previous_names":["zeldan/your-own-dependency-injection-framework"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeldan%2Fyour-own-dependency-injection-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeldan%2Fyour-own-dependency-injection-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeldan%2Fyour-own-dependency-injection-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeldan%2Fyour-own-dependency-injection-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zeldan","download_url":"https://codeload.github.com/zeldan/your-own-dependency-injection-framework/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248289928,"owners_count":21078922,"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":["dependency-injection","dependency-injection-framework","java","java-tutorial","tutorial-code"],"created_at":"2025-04-10T20:22:02.297Z","updated_at":"2025-04-10T20:22:02.906Z","avatar_url":"https://github.com/zeldan.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# your-own-dependency-injection-framework\n\n![Build Status](https://github.com/zeldan/your-own-dependency-injection-framework/actions/workflows/maven.yml/badge.svg)\n\nThis is a small project that demonstrates how to build your own dependency injection framework. \n\nIt supports **constructor** and **field** injection.\n\n- The framework itself can be found under the \"com.di.framework\" package.\n- Sample applications are available under the tests.\n\n### How to use\n\n##### 1. Define how you want to map interfaces to their implementations.\n\n```java\npublic class DependencyInjectionConfig extends AbstractModule {\n    \n    @Override\n    public void configure() {\n        createMapping(GreetingService.class, WelcomeServiceImpl.class);\n        createMapping(Logger.class, QuietLoggerImpl.class);\n    }\n}\n```\n\n##### 2. Add **@OwnInject** annotation to the constructor or fields.\n\n```java\npublic class ConstructorInjectionClient {\n    \n    private final GreetingService service;\n    private final Logger logger;\n    \n    @OwnInject\n    public ConstructorInjectionClient(final GreetingService service, final Logger logger) {\n        this.service = service;\n        this.logger = logger;\n    }\n}\n```\n\nOR\n\n```java\npublic class FieldInjectionClient {\n    \n    @OwnInject\n    private GreetingService service;\n    \n    @OwnInject\n    private Logger logger;\n\n}\n```\n\n##### 3. Use **OwnDi** to get your injected class.\n\n```java\npublic class SampleAppToTryDependencyInjection {\n    \n    public static void main(final String[] args) throws Exception {\n        final OwnDiFramework ownDi = OwnDi.getFramework(new DependencyInjectionConfig());\n        final ConstructorInjectionClient constructorInjectionClient = (ConstructorInjectionClient) ownDi.inject(ConstructorInjectionClient.class);\n    }\n\n}\n```\n\n### How It Works\n\nThe two main classes are **AbstractModule** and **OwnDiFramework**.\n \n* **AbstractModule** contains interfaces with their implementations (subclasses).\n* **OwnDiFramework** performs the injection via Java reflection. It checks that the constructor or fields are annotated with the **@OwnInject** annotation.\n \n\n### Running Tests\n\nTo execute tests, use the Maven Wrapper included in the project. Run the following command from the root directory of the project:\n\n```sh\n./mvnw test\n```\n\nThis command will compile the project with Java 21 and run all the tests using JUnit.\n\nIf you encounter any issues or have any questions, please refer to the documentation or reach out for support.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeldan%2Fyour-own-dependency-injection-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeldan%2Fyour-own-dependency-injection-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeldan%2Fyour-own-dependency-injection-framework/lists"}