Injection with heritage and CDI

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Injection with heritage and CDI

Otávio Gonçalves de Santana-2

Hey, I have a question about heritage and CDI.
Given two interfaces: 
  • Car interface
  • SportCar that extends Car

interface Car{
}

interface SportCar extends Car{
}


class DefaultCar implements Car {
}

@FerrariQualifier
class DefaultSportCar implements SportCar {
}

What I would like to inject:

@Inject
private Car car; //inject DefaultCar

@Inject
@FerrariQualifier
private Car ferrari; //inject DefaultSportCar


@Inject
private SportCar sportCar;//inject DefaultSportCar


How can I do that?

--
Otávio Gonçalves de Santana

_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Injection with heritage and CDI

Romain Manni-Bucau
Hi Otavio

Not sure it firts cdi-dev bit you can @Default @Ferrari @Typed(SportCar.class) the nice red car to exclude it from Car type and keep Car injection using DefaultCar and SportCar using the ferrari or implicit default qualifier.

But the sample sounds like a misusage of qualifier so maybe check it is really what you and to do.


Le 8 juil. 2017 16:27, "Otávio Gonçalves de Santana" <[hidden email]> a écrit :

Hey, I have a question about heritage and CDI.
Given two interfaces: 
  • Car interface
  • SportCar that extends Car

interface Car{
}

interface SportCar extends Car{
}


class DefaultCar implements Car {
}

@FerrariQualifier
class DefaultSportCar implements SportCar {
}

What I would like to inject:

@Inject
private Car car; //inject DefaultCar

@Inject
@FerrariQualifier
private Car ferrari; //inject DefaultSportCar


@Inject
private SportCar sportCar;//inject DefaultSportCar


How can I do that?

--
Otávio Gonçalves de Santana

_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.


_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Injection with heritage and CDI

Martin Kouba
Hi all,

I think Romain's workaround would not work for the second injection
point, i.e. for @Inject @FerrariQualifier Car ferrari because
@Typed(SportCar.class) DefaultSportCar would remove the Car from the
bean types of DefaultSportCar.

I agree that it looks like an incorrect usage of qualifiers though.

Martin

Dne 8.7.2017 v 16:36 Romain Manni-Bucau napsal(a):

> Hi Otavio
>
> Not sure it firts cdi-dev bit you can @Default @Ferrari
> @Typed(SportCar.class) the nice red car to exclude it from Car type and
> keep Car injection using DefaultCar and SportCar using the ferrari or
> implicit default qualifier.
>
> But the sample sounds like a misusage of qualifier so maybe check it is
> really what you and to do.
>
>
> Le 8 juil. 2017 16:27, "Otávio Gonçalves de Santana"
> <[hidden email] <mailto:[hidden email]>>
> a écrit :
>
>
>     Hey, I have a question about heritage and CDI.
>     Given two interfaces:
>
>       * Car interface
>       * SportCar that extends Car
>
>
>     interface  Car{
>     }
>
>     interface  SportCarextends  Car{
>     }
>
>
>     class  DefaultCarimplements  Car{
>     }
>
>     @FerrariQualifier
>     class  DefaultSportCarimplements  SportCar{
>     }
>
>     What I would like to inject:
>
>     @Inject
>     private  Car car;  //inject DefaultCar
>
>     @Inject
>     @FerrariQualifier
>     private  Car ferrari;  //inject DefaultSportCar
>
>
>     @Inject
>     private  SportCar sportCar;//inject DefaultSportCar
>
>
>
>     How can I do that?
>
>     --
>     Otávio Gonçalves de Santana
>
>
>     twitter: http://twitter.com/otaviojava <http://twitter.com/otaviojava>
>     site: _http://about.me/otaviojava_
>
>
>     _______________________________________________
>     cdi-dev mailing list
>     [hidden email] <mailto:[hidden email]>
>     https://lists.jboss.org/mailman/listinfo/cdi-dev
>     <https://lists.jboss.org/mailman/listinfo/cdi-dev>
>
>     Note that for all code provided on this list, the provider licenses
>     the code under the Apache License, Version 2
>     (http://www.apache.org/licenses/LICENSE-2.0.html
>     <http://www.apache.org/licenses/LICENSE-2.0.html>). For all other
>     ideas provided on this list, the provider waives all patent and
>     other intellectual property rights inherent in such information.
>
>
>
>
> _______________________________________________
> cdi-dev mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/cdi-dev
>
> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>

--
Martin Kouba
Senior Software Engineer
Red Hat, Czech Republic
_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
Loading...