block-quote On this pagechevron-down
copy Copy chevron-down
Basic Concepts DepIn is a dependency Injection tool that written in java
The simples usage of this library is:
Copy DefaultClass defaultClass = InstanceBuilder.init(DefaultClass.class).build(); This way, we create a defaultClass instance with all dependencies.
Note that we create dependencies of this instance from scratch .
If we want to pass spesific argument to instance's constructor method, we may use:
We use withArgs(Object... args) chain method for injecting arguments with constructor
Copy ExampleClass ec = InstanceBuilder
.init(ExampleClass.class)
.withArgs("ConstructorStringArg")
.build(); There is other ways to instantiate classes. For example, setters. We can simply inject dependencies with setters like this:
Firstly, we need a map to store and match setter and their arguments
Copy Map<String,Object> setterMap; And then, we need to describe our setter methods and their arguments
Copy setterMap.put("setSecretString","Selam"); Finally, we can use our map in withSetters(Map<String,Object> setters) chain method to create instance
Copy ExampleClass ec = InstanceBuilder
.init(ExampleClass.class)
.withSetters(setterMap)
.build(); We can similarly inject our dependencies directly with fields.
We just use withFields(Map<String,Object> setters) chain method.
This is inject the spesific fields that named in map with the corresponding object arguments