hendryluk / cormo

.NET Application Framework based on Spring and Java EE CDI
MIT License
5 stars 4 forks source link

Qualifiers with Members #8

Open hendryluk opened 9 years ago

hendryluk commented 9 years ago

Currently when resolving components, Cormo matches qualifiers using only their types. According to CDI spec however, attribute properties can be used to further discriminate a qualifier, which helps reducing the number of qualifiers needed. Ref: http://docs.jboss.org/weld/reference/latest/en-US/html/injection.html#_qualifiers_with_members

E.g.

public class PayByAttribute: QualifierAttribute
{
   public PaymentType PaymentType {get; set;}
}

Then we select one of the possible property values when applying the qualifier:

[Inject, PayBy(PaymentType.Check)] PaymentProcessor _checkPayment;

We can force the container to ignore a member of a qualifier type by annotating the property with [Nonbinding] attribute.

public class PayByAttribute: QualifierAttribute
{
   public PaymentType PaymentType {get; set;}
   [NonBinding] string Comment {get; set;}
}

The same should also be applied on interceptor bindings and mixin-bindings. https://docs.jboss.org/weld/reference/1.0.0/en-US/html/interceptors.html#d0e3527

E.g.

[Transactional(RequiresNew=false)]
public class RequiresNewTransactionInterceptor: IAroundInvokeInterceptor
{
}