11 Nisan 2022 Pazartesi

Jakarta EE Instance Arayüzü

Giriş
Açıklaması şöyle
A more powerful solution is Instance (resembles Spring’s ObjectProvider, and extends Provider) because it comes with

an iterator, which allows running for-loops over multi-valued dependencies (0..n)
a stream() method
methods for checking the availability and uniqueness of the dependency
Açıklaması şöyle
The following table summarizes the return value of the three boolean check methods, depending on the number of provided bean instances:                               

# OF INSTANCES ISRESOLVABLE ISUNSATISFIED ISAMBIGUOUS
0                         false                 true                         false
1                         true                         false                 false
>1                         false                 false                 true
Instance also allows applying additional filters (based on type and qualifier) when invoking its “select()” method, which is most useful in combination with programmatic injection
Örnek
Şöyle yaparız
@Inject
Instance<Pet> petInstances;

...

// loop over instances:
for (Pet pet : petInstances) {
  ...
}

// instance stream:
petInstances.stream().forEach(...);

// boolean check methods:
petInstances.isResolvable();
petInstances.isUnsatisfied();
petInstances.isAmbiguous();

Hiç yorum yok:

Yorum Gönder

Bean Validation @GroupSequence Anotasyonu

Örnek Elimizde şöyle bir kod olsun public class SampleRequest {   @NotNull   LocalDate startDate;   @NotNull   LocalDate endDate;   @AssertT...