{"id":20807800,"url":"https://github.com/devrezaur/spring-boot-dependency-injection","last_synced_at":"2025-07-30T05:06:49.273Z","repository":{"id":195171447,"uuid":"691967323","full_name":"DevRezaur/spring-boot-dependency-injection","owner":"DevRezaur","description":null,"archived":false,"fork":false,"pushed_at":"2023-09-15T09:15:17.000Z","size":65,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-12T03:46:44.846Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/DevRezaur.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-09-15T09:14:09.000Z","updated_at":"2023-09-16T19:54:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"88a60f1a-a62d-4d64-9fc6-b9fcb3261081","html_url":"https://github.com/DevRezaur/spring-boot-dependency-injection","commit_stats":null,"previous_names":["devrezaur/spring-boot-dependency-injection"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DevRezaur/spring-boot-dependency-injection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRezaur%2Fspring-boot-dependency-injection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRezaur%2Fspring-boot-dependency-injection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRezaur%2Fspring-boot-dependency-injection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRezaur%2Fspring-boot-dependency-injection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevRezaur","download_url":"https://codeload.github.com/DevRezaur/spring-boot-dependency-injection/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRezaur%2Fspring-boot-dependency-injection/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267814698,"owners_count":24148329,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"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":[],"created_at":"2024-11-17T19:42:43.245Z","updated_at":"2025-07-30T05:06:49.215Z","avatar_url":"https://github.com/DevRezaur.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dependency Injection (DI) \u0026 Inversion of Control (IoC)\n\n### Dependency Injection (DI)\n\nClasses often require references to other classes. For example, a **Programmer** class might\nneed a reference to an **Computer** class. These required classes are called dependencies, and in this example the\n**Programmer** class is dependent on having an instance of the **Computer** class to run.\n\nAnd dependency injection is the mechanism of providing the dependencies to the dependent class.\n\nIn our case, providing the **Computer** reference to the **Programmer** class.\n\n### Inversion of Control (IoC)\n\nInversion of control is a programming principal that transfers the responsibility of Dependency Injection (DI) to some\nmechanism or framework.\n\nBasically it transfers the control to the framework, hence the name inversion of control (IoC).\n\n# Example\n\nLet's imagine we have two Java class. **Programmer** \u0026 **Computer** as below.\n\n```java\n\npublic class Programmer {\n\n    private String name;\n\n    // Reference of Computer class\n    private Computer computer;\n\n    public Programmer(String name, Computer computer) {\n        this.name = name;\n        this.computer = computer;\n    }\n\n    // Getters \u0026 setters\n}\n\n```\n\n```java\n\npublic class Computer {\n\n    private String brand;\n\n    public Computer(String brand) {\n        this.brand = brand;\n    }\n\n    // Getters \u0026 setters\n}\n\n```\n\nWe can see that **Programmer** class contains a reference of **Computer** class. In other words, **Programmer** class \\\nhas dependency on **Computer** class.\n\nNow if we want to create an object of **Programmer** class, we need to pass a reference of **Computer** class. Like\nbelow.\n\n```java\n\npublic class MainClass {\n\n    public static void main(String[] args) {\n\n        Computer computer = new Computer(\"Dell\");\n\n        // Injecting the dependency manually. This is called manual dependency injection\n        Programmer programmer = new Programmer(\"Rezaur\", computer);\n    }\n}\n\n```\n\nNow if we pass the responsibility of injecting the depoency to a framework (i.e. spring framework), then it will be\ncalled inversion of control (IoC). Example given below.\n\n```java\n\n@SpringBootApplication\npublic class MainClass {\n\n    public static void main(String[] args) {\n        ApplicationContext context = SpringApplication.run(MainClass.class, args);\n\n        // Letting framework handle the dependency injection\n        // We are not providing the dependency\n        Programmer p1 = context.getBean(Programmer.class);\n        p1.printDetails();\n    }\n}\n\n```\n\n#### N.B: Please go through the code base for detailed information\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevrezaur%2Fspring-boot-dependency-injection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevrezaur%2Fspring-boot-dependency-injection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevrezaur%2Fspring-boot-dependency-injection/lists"}