Advanced

This page covers general purpose of usage scenarios for our project

When we have complex class structures and relations, we can simply represent them as some formats such as JSON.

Here is a simple example of the situation:

[
    {
        "id": "myCat",
        "target": "com.example.Cat"
        "args":[":s/Pamuk",":i/5"]
    },
    {
        "id": "myDog",
        "target": "com.example.Dog"
        "fields": [
            {"name":"name","value":":s/Karabaş"},
            {"name":"age", "value":":i/4"}
        ]
    },
    {
        "id": "catndog",
        "target":"com.example.CatNDog"
        "fields":[
            {"name":"cat", "value":"@myCat"},
            {"name":"dog", "value":"@myDog"},
        ]
    }
]

This JSON file represents our class structures and relations with each other. DepIn can read this file and generates instances of the classes that described there.

DepIn depIn = DepIn.JsonContext("src/test/resources/classmap.json");


// Creates Cat object, Dog object, CatNDog object
// and injects Cat and Dog object into CatNDog object
CatNDog catndog = depIn.getInstance("@catndog");

// Creates a cat instance with defined parameters in json file
Cat tekir = depIn.getInstance("@mycat");

Last updated