On 6/28/11 22:32 , Menzel, Toni wrote:
Hi,
Just wondering if @Service can be generic like so:
@Service Foo<Bar> service;
When declaring a service in a module using ModuleAssembly.addServices(..) it
does not look like having support for class objects as type literals.
Anything in Qi4J that is the pendant of Guice's TypeLiteral solution [1] ?
There are two things: one is the ability to declare a generic service,
and the other is the matching process during dependency injection. I had
a look and the current Qi4j service dependency code throws away too much
generics to be able to do that, so I fixed this in the Qi4j 2.0 code I'm
working on now.
Essentially you will be able to declare the service like so:
public static interface Foo<T>
{
T get();
}
@Mixins(StringService.Mixin.class)
public static interface StringService
extends Foo<String>, ServiceComposite
{
class Mixin
implements Foo<String>
{
@Override
public String get()
{
return "A";
}
}
}
@Mixins(LongService.Mixin.class)
public static interface LongService
extends Foo<Long>, ServiceComposite
{
class Mixin
implements Foo<Long>
{
@Override
public Long get()
{
return 1L;
}
}
}
}
and then just add LongService.class and StringService.class to the
assembly. I.e. in the assembly there's no generics, but the actual
service itself may be. Then, during lookup you can do this:
@Service
Foo<String> stringService;
and
@Service
Foo<Long> longService;
I had to fix the dependency model quite a bit to get this to work, so
it's just a first draft. No idea how it will work with more complicated
cases such as if the above uses type variables (@Service Foo<T> foo).
*If* we do the suggested change for EntityFinder into being Finder<T>
then this is needed by internal lookups anyway, so it was good that you
brought it up.
Now the question still remains: when shall I commit all this stuff? I
have TONS of changes that needs to be pushed to the repo, but I
understand we'd want to do a 1.3.1 first. Niclas, any ideas on that?
regards, Rickard
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev