Feature Overview
This feature injects dependency. See DI(Dependency Injection) for more details.
This feature injects dependency. See DI(Dependency Injection) for more details.
You need to configure the beans.json
file should you want to use the named beans.
public class InjectDemo {
@inject
private Case c1;
@inject('demo')
private Case c2;
}
public class InjectDemo {
private Case c1 = (Case)Sweet.getBean(Case.class);
private Case c2 = (Case)Sweet.getBean('demo');
}
@inject
works for two scenarios.
To inject a named bean, you need to configure it in the beans.json
like this:
[
{
"name": "demo",
"type": "Case"
}
]
To inject a typed bean, you need to bind the type first.
Sweet.bind(Case.class, Account.class); // Bind Case.class to be created by Account.class
Sweet.bindObject(Case.class, mockCase); // Bind Case.class to a created object
If no bindings are found, the original type will be used to create the instance.
Contribute on Github! Edit this section.