@Controller
and @Service
DiscountCalculator
component was defined with predefined prop discount
, as default instance for injection. discounter
will be an instance of DiscountCalculator
class and discount
value will be 10
. By default, DiscountCalculator
will be singleton, but this behavior can be changed.@Autowired(id?: string)
- sets method or property which will be provided with dependencies. Have one optional parameter id with default value "default"
. If you use define
method for configuring instances, autowired will find that instance by passed id
for injection. Note, id
will work only for class properties, methods will ignore it.
@Inject(id?: string)
- define dependency by id
for parameter. It can be used for constructor and method injection. If default
instance is needed, just omit usage of this decorator.FoodManager
and MedicineManager
dependencies will be automatically injected. MedicineManager
will be injected by pets
id.@Autowired()
will be injected.@Autowired()
will be injected. But id
parameter of @Autowired()
will be ignored. For classifying dependencies use @Inject()
decorator. Any method can be used for injection.define
function for itid
(this id can be passed into @Autowired
and/or @Inject
decorators for proper instance type injection).setSingleton(id: string, ...)
and setScoped(id: string, ...)
Foo
class in define
function:baz
must be injected automatically, but bar
and far
got predefined values:undefined
will be automatically injected. props
accepts only properties, not methods, so it's fully save. Same thing with constructorArgs
. It's strict tuple.