{"id":18816148,"url":"https://github.com/ljacqu/dependencyinjector","last_synced_at":"2025-08-21T11:33:41.373Z","repository":{"id":9309476,"uuid":"61565876","full_name":"ljacqu/DependencyInjector","owner":"ljacqu","description":"Lightweight dependency injector","archived":false,"fork":false,"pushed_at":"2024-12-18T05:50:34.000Z","size":676,"stargazers_count":32,"open_issues_count":17,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-18T06:43:11.862Z","etag":null,"topics":["application-initializer","dependency","dependency-injection","injection","injector","ioc","ioc-container","java"],"latest_commit_sha":null,"homepage":null,"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/ljacqu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-06-20T17:11:24.000Z","updated_at":"2023-03-14T17:26:40.000Z","dependencies_parsed_at":"2023-02-16T18:32:19.461Z","dependency_job_id":"6f29a6ee-f055-4e3b-bd08-ee7f23b94da3","html_url":"https://github.com/ljacqu/DependencyInjector","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljacqu%2FDependencyInjector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljacqu%2FDependencyInjector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljacqu%2FDependencyInjector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljacqu%2FDependencyInjector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ljacqu","download_url":"https://codeload.github.com/ljacqu/DependencyInjector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230511479,"owners_count":18237657,"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":["application-initializer","dependency","dependency-injection","injection","injector","ioc","ioc-container","java"],"created_at":"2024-11-07T23:52:37.646Z","updated_at":"2024-12-19T23:14:15.347Z","avatar_url":"https://github.com/ljacqu.png","language":"Java","readme":"## Lightweight Dependency Injector\n[![Build Status](https://travis-ci.org/ljacqu/DependencyInjector.svg?branch=master)](https://travis-ci.org/ljacqu/DependencyInjector)\n[![Coverage Status](https://coveralls.io/repos/github/ljacqu/DependencyInjector/badge.svg?branch=master)](https://coveralls.io/github/ljacqu/DependencyInjector?branch=master)\n[![Javadocs](http://www.javadoc.io/badge/ch.jalu/injector.svg)](http://www.javadoc.io/doc/ch.jalu/injector)\n[![Code Climate](https://codeclimate.com/github/ljacqu/DependencyInjector/badges/gpa.svg)](https://codeclimate.com/github/ljacqu/DependencyInjector)\n\nSimple but customizable dependency injector for Java 1.8 and above.\n\n\n### Why use it\n- Very lightweight (only has `javax.inject` and `javax.annotation-api` as dependency)\n- Allows gradual transition to injection for existing projects\n- You can implement your own injection methods and behaviors\n- Support for projects with optional dependencies\n\n### Integrating it\nUsing Maven, you can get the injector by adding this to your pom.xml:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ech.jalu\u003c/groupId\u003e\n    \u003cartifactId\u003einjector\u003c/artifactId\u003e\n    \u003cversion\u003e1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Simple example\nBy default, the injector supports **constructor injection** and **field injection**.\nConsider the following class skeletons:\n\n```java\npublic class Settings {\n  // regular class\n}\n\npublic class Messages {\n  private File messagesFile;\n\n  @Inject\n  Messages(Settings settings) {\n    messagesFile = new File(settings.getLanguage() + \".txt\");\n  }\n}\n\npublic class CalculationService {\n  @Inject\n  private Messages messages;\n  \n  @Inject\n  private RoundingService roundingService;\n}\n\npublic class RoundingService {\n  private int precision;\n\n  @Inject\n  RoundingService(Settings settings) {\n    precision = settings.getPrecision();\n  }\n}\n```\n\nAt the startup of the application, we might only care about getting an instance of `CalculationService`. All other\nclasses are required by it to run, but we don't immediately care about them. With the injector, we don't have to\ndeal with those classes and can just retrieve what we actually want:\n\n```java\npublic class MyApp {\n\n  public static void main(String... args) {\n    Injector injector = new InjectorBuilder().addDefaultHandlers(\"com.example.my.project\").create();\n    CalculationService calcService = injector.getSingleton(CalculationService.class);\n    calcService.performCalculation();\n  }\n}\n```\n\n... That's all! No need to deal with creating any other classes, but you still have a setup that allows you to easily\nunit test or switch a component.\n\n--\u003e Full, runnable example can be found [here](https://github.com/ljacqu/DependencyInjector/tree/master/injector/src/test/java/ch/jalu/injector/demo).\n\n### Handlers\nYou may implement your own logic to instantiate classes and resolve dependencies. This allows you, for example, to\nimplement specific behavior for custom annotations.\nRead more on the Wiki: [Handlers explained](https://github.com/ljacqu/DependencyInjector/wiki/Handlers)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fljacqu%2Fdependencyinjector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fljacqu%2Fdependencyinjector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fljacqu%2Fdependencyinjector/lists"}