CDI supports direct field injection, parameter input of the initializer method, and constructor parameter injector. From the CDI 1.0 specification:
3.7. Bean Constructors
bean, bean. Bean Bean.
bean . , bean, ; - ; ; .
3.7.1. Bean
Bean @Inject.
@SessionScoped
public class ShoppingCart implements Serializable {
private User customer;
@Inject
public ShoppingCart(User customer) {
this.customer = customer;
}
public ShoppingCart(ShoppingCart original) {
this.customer = original.customer;
}
ShoppingCart() {}
...
}
@ConversationScoped
public class Order {
private Product product;
private User customer;
@Inject
public Order(@Selected Product product, User customer) {
this.product = product;
this.customer = customer;
}
public Order(Order original) {
this.product = original.product;
this.customer = original.customer;
}
Order() {}
...
}
Bean @Inject, , Bean.
Bean @Inject, .
Bean @Disposes @Observes, .
Bean . Bean - .
, WELD-141, .