petite : Injection of an implementation of an interface

12 views
Skip to first unread message

moh....@googlemail.com

unread,
Jan 15, 2016, 6:58:24 AM1/15/16
to Jodders
Hi all,

i am playing with jodd petite.
My aim is to replace CDI (only used basic stuff like injection with annotation @Inject) in given application..

One "problem" is:

@PetiteBean
public class BeanA {
   
@PetiteInject
   
private IDoSmthService service;

}


public interface IDoSmthService {
     // few methods
}

@PetiteBean
public class DoSmthReallyWellService implements
IDoSmthService {

// implementation
}


petite will fail if BeanA will be wired.
"Beans references : .... not found for property"
Works as expected?

I am used by spring / cdi that injection like above will be performed properly (if only one implementation of the interface is available).

Do i have to use names for PetiteInject and PetiteBean in my case?


Thank you!

Greetz
Sascha


Jodders

unread,
Jan 18, 2016, 9:04:49 AM1/18/16
to Jodders
hi!

Yes, you are totally right!

We don't have the "if only one implementation of the interface is available" feature - but that is a great idea to have one.

Hence, you need to name your DoSmthReallyWellService bean as "IDoSmthService" so petite know the real name.

But this gives some nice ideas! For example, if bean is not found, we can use alternative set of names, from all the interfaces it implements. So when bean is registered by default name (not explicit one), we can simply register these 'add-on' names, and this is going to work.

I will add this feature very soon, for 3.7!

moh....@googlemail.com

unread,
Jan 18, 2016, 9:35:06 AM1/18/16
to Jodders
I have used names next to the annotation PetiteBean and PetiteInject - works as expected :-)

I am looking forward to 3.7 - sounds awesome :-)


Thx!

Igor Spasic

unread,
Feb 20, 2016, 2:45:07 PM2/20/16
to moh....@googlemail.com, Jodders
Heya!

Just committed a change that allows what you asked, using interface names if only one implementation is registered.

Yeah!

--
Jodd - The Unbearable Lightness of Java - http://jodd.org
---
You received this message because you are subscribed to the Google Groups "Jodders" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jodders+u...@googlegroups.com.
To post to this group, send email to jod...@googlegroups.com.
Visit this group at https://groups.google.com/group/jodders.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages