{"id":20397632,"url":"https://github.com/jwdeveloper/dependance","last_synced_at":"2026-05-30T18:31:09.640Z","repository":{"id":196153644,"uuid":"694722874","full_name":"jwdeveloper/DepenDance","owner":"jwdeveloper","description":"Simple and easy to use dependecy injection container for Java","archived":false,"fork":false,"pushed_at":"2024-09-07T10:25:41.000Z","size":297,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-05T01:14:17.000Z","etag":null,"topics":["containers","dependance","dependecy-container","dependecy-injection","dependecy-injection-container","di","dic","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/jwdeveloper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":"FUNDING.yml","license":"license.txt","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},"funding":{"patreon":"jwdeveloper","custom":["https://www.buymeacoffee.com/jwdev"]}},"created_at":"2023-09-21T15:02:43.000Z","updated_at":"2024-09-07T10:25:44.000Z","dependencies_parsed_at":"2023-09-21T20:08:12.954Z","dependency_job_id":"f9ff6a38-e435-4e6c-843e-98d3dc578323","html_url":"https://github.com/jwdeveloper/DepenDance","commit_stats":null,"previous_names":["jwdeveloper/dependance"],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/jwdeveloper/DepenDance","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwdeveloper%2FDepenDance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwdeveloper%2FDepenDance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwdeveloper%2FDepenDance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwdeveloper%2FDepenDance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwdeveloper","download_url":"https://codeload.github.com/jwdeveloper/DepenDance/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwdeveloper%2FDepenDance/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33705207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-30T02:00:06.278Z","response_time":92,"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":["containers","dependance","dependecy-container","dependecy-injection","dependecy-injection-container","di","dic","java"],"created_at":"2024-11-15T04:15:53.898Z","updated_at":"2026-05-30T18:31:09.623Z","avatar_url":"https://github.com/jwdeveloper.png","language":"Java","funding_links":["https://patreon.com/jwdeveloper","https://www.buymeacoffee.com/jwdev"],"categories":[],"sub_categories":[],"readme":"\n\u003cdiv align=\"center\" \u003e\n\n\n\u003ca target=\"blank\" \u003e\n\n\u003cimg src=\"https://raw.githubusercontent.com/jwdeveloper/DepenDance/master/Tools-Readme/src/main/resources/logo.svg\" width=\"15%\" \u003e\n\u003c/img\u003e\n\u003c/a\u003e\n\n\u003c/div\u003e\n\n\n\u003cdiv align=\"center\" \u003e\n\n\u003ch1\u003eDepenDance\u003c/h1\u003e\n\n\n*💉 Inject Simplicity, Eject Complexity 🪲*\n\n\n\u003cdiv align=\"center\" \u003e\n\n\n\u003ca href=\"https://jitpack.io/#jwdeveloper/DepenDance\" target=\"blank\" \u003e\n\n\u003cimg src=\"https://jitpack.io/v/jwdeveloper/DepenDance.svg\" width=\"20%\" \u003e\n\u003c/img\u003e\n\u003c/a\u003e\n\n\n\n\u003ca href=\"https://discord.gg/2hu6fPPeF7\" target=\"blank\" \u003e\n\n\u003cimg src=\"https://img.shields.io/badge/Discord-%235865F2.svg?style=for-the-badge\u0026logo=discord\u0026logoColor=white\" \u003e\n\u003c/img\u003e\n\u003c/a\u003e\n\n\n\n\u003ca target=\"blank\" \u003e\n\n\u003cimg src=\"https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge\u0026logo=openjdk\u0026logoColor=white\" \u003e\n\u003c/img\u003e\n\u003c/a\u003e\n\n\u003c/div\u003e\n\n\u003c/div\u003e\n\n\n\n\n\n```xml\n\n    \u003crepositories\u003e\n        \u003crepository\u003e\n            \u003cid\u003ejitpack.io\u003c/id\u003e\n            \u003curl\u003ehttps://jitpack.io\u003c/url\u003e\n        \u003c/repository\u003e\n    \u003c/repositories\u003e\n    \u003cdependency\u003e\n        \u003cgroupid\u003ecom.github.jwdeveloper.DepenDance\u003c/groupid\u003e\n        \u003cartifactid\u003eDepenDance-Full\u003c/artifactid\u003e\n        \u003cversion\u003e0.0.20-Release\u003c/version\u003e\n    \u003c/dependency\u003e     \n```\n\n\nDepandance is the dependency injection container library. Is is quite compacts and has a lot of features you can find in the more popular DI container libraries. ## What are the dependecies? Dependecies is the fancy word for a class consturctor parameters. So the objects certain class depends on/ ## What is the dependecy injection? Is is one of the programming design patters, watch great video about it [Video](https://www.youtube.com/watch?v=J1f5b4vcxCQ) ## What is the dependecy injection container? It is library that helps to create instance of object with all its `dependecines`. At the beggining you need to register the dependecines classess to the container, then any class that was registed, can be obtained for the container.\n\u003ch1\u003eFeatures\u003c/h1\u003e\n\n\n- [x] Injecting object via constructor\n\n- [x] Method object providers\n\n- [x] Class Scanner to avoid manual registration [Scanner](#autoscan)\n\n- [x] You need to get [List of objects](#lists) in the constructor, no problem\n\n- [x] Create [object instance](#object-instances) by yourself and register it to container!\n\n- [x] Object lifetimes [SINGLETON, TRANSIENT] [see](#basic)\n\n- [x] [Generic types](#generic-types)\n\n- [x] [Many constructors](#manyconstructors)\n\n- [x] Highly customizable, adjust container with build in [events](#events) system\n\n\n\u003ch1\u003eTutorial\u003c/h1\u003e\n\n\n[01 Basic](https://github.com/jwdeveloper/DepenDance?tab=readme-ov-file#01-Basic) \n\n[02 Object Instances](https://github.com/jwdeveloper/DepenDance?tab=readme-ov-file#02-Object-Instances) \n\n[03 Lists](https://github.com/jwdeveloper/DepenDance?tab=readme-ov-file#03-Lists) \n\n[04 Events](https://github.com/jwdeveloper/DepenDance?tab=readme-ov-file#04-Events) \n\n[05 Generic Types](https://github.com/jwdeveloper/DepenDance?tab=readme-ov-file#05-Generic-Types) \n\n[06 AutoScan](https://github.com/jwdeveloper/DepenDance?tab=readme-ov-file#06-AutoScan) \n\n[07 Overriding](https://github.com/jwdeveloper/DepenDance?tab=readme-ov-file#07-Overriding) \n\n[08 ManyConstructors](https://github.com/jwdeveloper/DepenDance?tab=readme-ov-file#08-ManyConstructors) \n\n[09 Fields](https://github.com/jwdeveloper/DepenDance?tab=readme-ov-file#09-Fields) \n\n[10 Methods](https://github.com/jwdeveloper/DepenDance?tab=readme-ov-file#10-Methods) \n\n[11 ResolveParameters](https://github.com/jwdeveloper/DepenDance?tab=readme-ov-file#11-ResolveParameters) \n\n\n\n### 01 Basic\n\n```java\npublic class _01_Basic {\n\n\n    public static void main(String[] args) {\n        /*\n           - Singleton There will be only one instance of object created by container\n           - Transient everytime `container.find` is used new instance of object is created\n         */\n\n        DependanceContainer container = Dependance.newContainer()\n                .registerTransient(Shop.class, LocalShop.class) //registration interface to implementation\n                .registerSingleton(Config.class)\n                .registerSingleton(ShopManager.class)\n                .build();\n\n\n        ShopManager shopManager1 = container.find(ShopManager.class);\n        ShopManager shopManager2 = container.find(ShopManager.class);\n\n        Shop shop1 = container.find(Shop.class);\n        Shop shop2 = container.find(Shop.class);\n\n\n        Assert.assertEquals(shopManager1, shopManager2);\n        System.out.println(\"There always same instance of shop manager\");\n\n        Assert.assertEquals(shopManager1.getConfig(), shopManager2.getConfig());\n        System.out.println(\"There always same instance of config\");\n\n        Assert.assertNotEquals(shop1, shop2);\n        System.out.println(\"There are different instances of shop\");\n    }\n} \n```\n### 02 Object Instances\n\n```java\npublic class _02_Object_Instances\n{\n    public static void main(String[] args)\n    {\n        Config myConfigInstance = new Config();\n        DependanceContainer container = Dependance.newContainer()\n                .registerSingleton(Config.class, myConfigInstance) //in case we want to make instance manually we can put object as second argument\n                .registerTransient(LocalShop.class,(di)-\u003e\n                {\n                    //more complex case, we want to find or put manually arguments to created instance\n                    //for that we can use lamda resolver that has container as input, and object instance as output\n                    var config = (Config)di.find(Config.class);\n                    var shop = new LocalShop(config);\n                    System.out.println(\"Shop has been created: \"+shop);\n                    return shop;\n                })\n                .build();\n\n        Config config = container.find(Config.class);\n        LocalShop shop1 = container.find(LocalShop.class);\n        LocalShop shop2 = container.find(LocalShop.class);\n\n        Assert.assertEquals(myConfigInstance,config);\n        System.out.println(\"Config has same instance\");\n\n        Assert.assertNotEquals(shop1,shop2);\n        System.out.println(\"Shops has different instances\");\n    }\n} \n```\n### 03 Lists\n\n```java\npublic class _03_Lists {\n    public static void main(String[] args) {\n        DependanceContainer container = Dependance.newContainer()\n                .registerSingleton(Config.class)\n                .registerTransient(Shop.class, OnlineShop.class)\n                .registerTransient(Shop.class, LocalShop.class)\n                .registerTransientList(Shop.class)\n                .build();\n\n\n        List\u003cShop\u003e shops = (List\u003cShop\u003e) container.find(List.class, Shop.class);\n\n\n        for (var shop : shops) {\n            System.out.println(\"Shops: \" + shop.getClass().getSimpleName());\n        }\n        Assert.assertEquals(2, shops.size());\n    }\n\n\n} \n```\n### 04 Events\n\n```java\npublic class _04_Events {\n    public static void main(String[] args) {\n        DependanceContainer container = Dependance.newContainer()\n                .registerSingleton(Shop.class, LocalShop.class)\n                .registerSingleton(Shop.class, OnlineShop.class)\n                .configure(config -\u003e\n                {\n                    config.onInjection(_04_Events::onInjection);\n                    config.onRegistration(_04_Events::onRegistration);\n                })\n                .build();\n\n        Object shops = container.find(Shop.class, String.class);\n    }\n\n\n    private static Boolean onRegistration(OnRegistrationEvent event) {\n        System.out.println(\"onRegistration event: \" + event.registrationInfo().implementation().getSimpleName());\n        return true; //If false `container.find` injection is not registered to container\n    }\n\n    private static Object onInjection(OnInjectionEvent event) {\n        var inputType = event.input();// searched class type provided as first parameters\n        var genericTypes = event.inputGenericParameters(); //list of generic types provided as second parameter\n        var outputObject = event.output(); //Target object instance type has not been found then output value is null\n        var container = event.container(); //access to DI container\n        var injectonMetadata = event.injectionInfo();\n\n        System.out.println(\"OnInjection input class: \" + inputType.getSimpleName());\n        System.out.println(\"OnInjection output class: \" + outputObject.getClass().getSimpleName());\n        System.out.println(\"OnInjection genericTypes: \" + genericTypes.length);\n        System.out.println(\"OnInjection metadata: \" + injectonMetadata.toString());\n        return outputObject;\n    }\n} \n```\n### 05 Generic Types\n\n```java\npublic class _05_Generic_Types {\n\n    public static void main(String[] args) {\n\n        var container = Dependance.newContainer()\n                .registerTransient(ExampleGenericsTypes.class)\n                .configure(configuration -\u003e\n                {\n                    /*\n                     * Since java is not storing information about generic type after compilation\n                     * we can not assign class with generic type to variable, so Repository\u003cMyGenericType\u003e.class is not possible\n                     * Therefor all cases with generic types (besides lists) must be handled manually in onInjection event\n                     */\n\n                    configuration.onInjection(injection -\u003e\n                    {\n                        if (!injection.input().isAssignableFrom(Repository.class)) {\n                            return injection.output();\n                        }\n\n                        var genericParameter = injection.inputGenericParameters()[0];\n                        if (genericParameter.equals(OnlineShop.class)) {\n                            return new Repository\u003cOnlineShop\u003e();\n                        }\n                        if (genericParameter.equals(LocalShop.class)) {\n                            return new Repository\u003cLocalShop\u003e();\n                        }\n                        return new Repository();\n                    });\n                })\n\n                .build();\n\n\n        //first parameter is class, second one is its generic parameter\n        var exampleGenericsTypes = container.find(ExampleGenericsTypes.class);\n\n        Assert.assertNotNull(exampleGenericsTypes);\n        Assert.assertNotNull(exampleGenericsTypes.getLocalShopRepository());\n        Assert.assertNotNull(exampleGenericsTypes.getOnlineShopRepository());\n\n    }\n\n    public static class ExampleGenericsTypes {\n\n        @Getter\n        private Repository\u003cOnlineShop\u003e onlineShopRepository;\n        @Getter\n        private Repository\u003cLocalShop\u003e localShopRepository;\n\n        public ExampleGenericsTypes(Repository\u003cOnlineShop\u003e onlineShopRepository,\n                                    Repository\u003cLocalShop\u003e localShopRepository) {\n            this.onlineShopRepository = onlineShopRepository;\n            this.localShopRepository = localShopRepository;\n        }\n    }\n\n\n} \n```\n### 06 AutoScan\n\n```java\npublic class _06_AutoScan {\n\n    /**\n     * To avoid boring manually registering Types to container\n     * use `scan` method that is looking for all Classes and Methods\n     * with annotation @Injection and register it automatically\n     */\n\n    public static void main(String[] args) {\n\n        /*\n         *  package under which code will be scanned should be scanned\n         *  scanner is looking for all Method and Classes that are having @Injection annotation\n         */\n\n        Class\u003c?\u003e rootClass = _06_AutoScan.class;\n\n        DependanceContainer container = Dependance.newContainer()\n                .scan(rootClass)\n                .scan(options -\u003e\n                {\n                    options.setRootPackage(rootClass);\n                    options.excludeClass(\"org.example.ExampleClass\");\n                    options.excludePackage(String.class.getPackageName());\n                })\n                .scan(rootClass, (scannedClasses, containerBuilder) -\u003e\n                {\n                    System.out.println(\"Hello from scanner those are found classes\");\n                    for (var clazz : scannedClasses)\n                    {\n                      System.out.println(clazz.getSimpleName());\n                    }\n                    System.out.println(\"============================================\");\n                })\n                .build();\n\n        Config config = container.find(Config.class);\n        ExampleClass exampleClass = container.find(ExampleClass.class);\n        OnlineShop onlineShop = container.find(OnlineShop.class);\n        ExampleScannClass exampleScannClass = container.find(ExampleScannClass.class);\n\n        Assert.assertNotNull(config);\n        Assert.assertNotNull(exampleClass);\n        Assert.assertNotNull(onlineShop);\n        Assert.assertNotNull(exampleScannClass);\n    }\n\n\n    /**\n     * This is equivalent of\n     * \u003cp\u003e\n     * container.registerTransient(OnlineShop.class,container1 -\u003e\n     * {\n     * System.out.println(\"Hello from the online shop factory\");\n     * return new OnlineShop();\n     * })\n     */\n    @Injection(lifeTime = LifeTime.TRANSIENT)\n    private static OnlineShop onlineShopFactory() {\n        System.out.println(\"Hello from the online shop factory\");\n        return new OnlineShop();\n    }\n\n\n    /**\n     * This is equivalent of\n     * \u003cp\u003e\n     * container.registerSingleton(ExampleScannClass.class);\n     */\n    @Injection(lifeTime = LifeTime.SINGLETON)\n    public static class ExampleScannClass {\n        public ExampleScannClass() {\n            System.out.println(\"Hello world!\");\n        }\n    }\n} \n```\n### 07 Overriding\n\n```java\npublic class _07_Overriding {\n    public static void main(String[] args) {\n\n        DependanceContainer container = Dependance.newContainer()\n                .registerTransient(Shop.class, OnlineShop.class)\n                .registerTransient(Shop.class, OfflineShop.class)\n                /**\n                 * By again declaring Shop but with different implementation (OnlineShop)\n                 * We are telling container to Override (OfflineShop) and always returns (OnlineShop)\n                 */\n                .build();\n\n        Shop shop = container.find(Shop.class);\n        Assert.assertEquals(OfflineShop.class, shop.getClass());\n        System.out.println(\"shop object is instance of OfflineShop Class\");\n    }\n} \n```\n### 08 ManyConstructors\n\n```java\npublic class _08_ManyConstructors\n{\n    /**\n     *  By the default the first constructor is always targeted for injecting parameters\n     *  However, sometimes class can have more than one constructor, or we want to use\n     *  specific one.\n     *\n     *  To do that use @Inject annotation over wanted constructor\n     *\n     */\n\n    public static void main(String[] args) {\n\n        DependanceContainer container = Dependance.newContainer()\n                .registerTransient(ExampleClass.class)\n                .registerTransient(ManyConstructorsExample.class)\n                .build();\n\n        ManyConstructorsExample example = container.find(ManyConstructorsExample.class);\n        Assert.assertNotNull(example);\n        System.out.println(\"It works!\");\n    }\n\n    public static class ManyConstructorsExample\n    {\n\n        public ManyConstructorsExample(String a, int b, boolean c)\n        {\n\n        }\n\n        @Inject\n        public ManyConstructorsExample(ExampleClass c)\n        {\n            System.out.println(\"Hello from constructor with ExampleClass parameter\");\n        }\n    }\n\n    public static class ExampleClass\n    {\n\n    }\n} \n```\n### 09 Fields\n\n```java\npublic class _09_Fields {\n\n\n    public static void main(String[] args) {\n        DependanceContainer container = Dependance.newContainer()\n                .registerTransient(_09_Fields.ExampleSerivce.class)\n                .registerTransient(_09_Fields.ExampleClass.class)\n                .build();\n\n        _09_Fields.ExampleSerivce example = container.find(_09_Fields.ExampleSerivce.class);\n        Assert.assertNotNull(example);\n        example.exampleClass.sayIt();\n    }\n\n    public static class ExampleSerivce {\n        @Inject\n        ExampleClass exampleClass;\n    }\n\n    public static class ExampleClass {\n        public void sayIt() {\n            System.out.println(\"Hello world!\");\n        }\n    }\n} \n```\n### 10 Methods\n\n```java\npublic class _10_Methods\n{\n    public static void main(String[] args) {\n        DependanceContainer container = Dependance.newContainer()\n                .registerTransient(_10_Methods.ExampleSerivce.class)\n                .registerTransient(_10_Methods.ExampleClass.class)\n                .build();\n\n        _10_Methods.ExampleClass example = container.find(_10_Methods.ExampleClass.class);\n        Assert.assertNotNull(example);\n        example.sayIt();\n    }\n\n    public static class ExampleSerivce\n    {\n        @Injection\n        _09_Fields.ExampleClass exampleClassProvider()\n        {\n            return new _09_Fields.ExampleClass();\n        }\n    }\n\n    public static class ExampleClass {\n        public void sayIt() {\n            System.out.println(\"Hello world!\");\n        }\n    }\n} \n```\n### 11 ResolveParameters\n\n```java\npublic class _11_ResolveParameters {\n    public static void main(String[] args) throws Exception {\n        DependanceContainer container = Dependance.newContainer()\n                .registerTransient(_11_ResolveParameters.ExampleWithGenerics.class)\n                .registerTransient(_11_ResolveParameters.ExampleClass.class)\n                .configure(config -\u003e\n                {\n                    config.onInjection(onInjectionEvent -\u003e\n                    {\n                        if (!onInjectionEvent.input().equals(ExampleWithGenerics.class)) {\n                            return onInjectionEvent.output();\n                        }\n\n                        var geneicsTyles = onInjectionEvent.inputGenericParameters()[0];\n                        if (!String.class.equals(geneicsTyles)) {\n                            return onInjectionEvent.output();\n                        }\n                        return new ExampleWithGenerics\u003cString\u003e();\n                    });\n                })\n                .build();\n\n        var method = _11_ResolveParameters.class.getDeclaredMethod(\n                \"sayHello\",\n                _11_ResolveParameters.ExampleWithGenerics.class,\n                _11_ResolveParameters.ExampleClass.class);\n\n        var parameters = container.resolveParameters(method);\n\n        method.invoke(null, parameters);\n    }\n\n\n    public static void sayHello(_11_ResolveParameters.ExampleWithGenerics\u003cString\u003e exampleService,\n                                _11_ResolveParameters.ExampleClass exampleClass) {\n\n        System.out.println(\"Hello world\");\n    }\n\n\n    public static class ExampleWithGenerics\u003cT\u003e {\n\n    }\n\n    public static class ExampleClass {\n\n    }\n} \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwdeveloper%2Fdependance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwdeveloper%2Fdependance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwdeveloper%2Fdependance/lists"}