{"id":18586339,"url":"https://github.com/kateyst/test-java","last_synced_at":"2025-05-16T06:34:31.479Z","repository":{"id":176985176,"uuid":"659810183","full_name":"KateySt/test-java","owner":"KateySt","description":null,"archived":false,"fork":false,"pushed_at":"2023-07-02T16:22:07.000Z","size":104,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-17T17:56:22.274Z","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/KateySt.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-06-28T15:53:15.000Z","updated_at":"2023-06-28T16:21:17.000Z","dependencies_parsed_at":"2023-07-10T23:16:30.047Z","dependency_job_id":null,"html_url":"https://github.com/KateySt/test-java","commit_stats":null,"previous_names":["kateyst/test-java"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KateySt%2Ftest-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KateySt%2Ftest-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KateySt%2Ftest-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KateySt%2Ftest-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KateySt","download_url":"https://codeload.github.com/KateySt/test-java/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254484410,"owners_count":22078754,"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":[],"created_at":"2024-11-07T00:37:57.343Z","updated_at":"2025-05-16T06:34:31.460Z","avatar_url":"https://github.com/KateySt.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dependency Injection Container\n\nThis is a simple dependency injection container implementation that provides a way to register components and perform dependency injection using annotations, similar to the Spring framework.\n\n## Annotations\n\n**@Component**: This annotation is applied to a class and indicates that the class is a component and should be registered in the dependency container.\n\n**@Autowired**: This annotation is applied to a constructor and indicates that the constructor should be used for dependency injection into the component.\n\n**@Qualifier**: This annotation is applied to constructor parameters and identifies the parameter by a string. It allows specifying which specific component implementation to use for dependency injection.\n\n**@PostConstructor**: This annotation is applied to a method that should be called immediately after the component instance is created.\n\n## Class DependencyContainer\n\nThis class represents the dependency container. It contains the main logic for registering components and injecting dependencies.\n\n- **instances**: A map that stores instances of registered components.\n- **circularDependencyCheckSet**: A set used for checking circular dependencies between components.\n- **preAddListeners and postAddListeners**: Lists of listeners that are called before and after adding components to the container.\n- **addPreAddListener and addPostAddListener**: Methods for adding listeners.\n- **registerComponent**: A method that registers a component in the container.\n- **getAutowiredConstructor**: A method that returns a constructor with the `@Autowired` annotation for a given class.\n- **getQualifierAnnotation**: A method that returns the `@Qualifier` annotation for a given array of constructor parameter annotations.\n- **getInstance**: A method that returns an instance of a component for a given class. If the instance is not found, it is created and registered.\n- **invokePostConstructMethods**: A method that invokes methods with the `@PostConstructor` annotation for a given component instance.\n- **getInstance**: A method that returns an instance of a component for a given class from the container.\n- **getComponentName**: A method that returns the component name based on the `@Component` annotation.\n\n## Interface ComponentListener\n\nThis interface defines the `onComponentAdded` method, which is called when a component is added to the container.\n\n## Component classes\n\nThe following component classes are provided as examples:\n\n- **ComponentA**: Represents a component that provides a `doSomething()` method.\n- **ComponentB**: Depends on `ComponentA` and is injected through the constructor.\n- **ComponentC**: Depends on `ComponentB` and is injected through the constructor. It also has a `@PostConstructor` method.\n- **ComponentD**: Depends on `ComponentB` and is injected through the constructor.\n\n## Execution result example\n\n1. Creat components:\n\n```\n@Component\npublic class ComponentA {\npublic void doSomething() {\nSystem.out.println(\"ComponentA: doSomething()\");\n}\n}\n```\n```\n@Component\npublic class ComponentB {\n    @Autowired\n    public ComponentB(ComponentA componentA) {\n    }\n}\n```\n```\n@Component\npublic class ComponentC {\n    @Autowired\n    public ComponentC(ComponentB componentB) {\n    }\n    @PostConstructor\n    public void init() {\n        System.out.println(\"ComponentC: Initialized\");\n    }\n}\n```\n```\n@Component\npublic class ComponentD {\n    @Autowired\n    public ComponentD(ComponentB componentB) {\n    }\n}\n```\n\n2.Main\n\n```\npublic class Main {\n    public static void main(String[] args) {\n        IoC.registerBean(new ComponentA());\n\n        ComponentA componentA = IoC.getBean(ComponentA.class);\n        componentA.doSomething();\n          }\n}\n``` \n\n**Result**:\n\n```\nComponentA: doSomething()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkateyst%2Ftest-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkateyst%2Ftest-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkateyst%2Ftest-java/lists"}