On 2011-01-09 07.10, Marc Grue wrote:
I'm working on a port of the DDDsample application to DCI-Qi4j, and I'm
experimenting with a version using ValueComposites for most data. But I get
a problem when I want to let a ValueComposite Object play a Role in a DCI
Context.
In order to Create the Context I need to pass in a SomeValue instance. But
when instantiating it first, all Mixins of that composite are instantiated
which causes the ContextInjectionProviderFactory to try to inject the
Context object that it can't find on the Context stack yet. Catch 22.
Instantiating SomeEntity doesn't seem to cause all Mixins in that composite
to be instantiated straight away. So there we get the Context object
correctly on the Context stack first (by the enactment call), and then it
gets injected into the @Context-annotated context field in EntityRole.Mixin.
The ContextInjectionWithValueTest below shows the problem - can you see a
way to get it working or what I'm missing? ContextInjectionWithEntityTest
works fine as a comparison.
Right, the main issue is that we eager-create the mixins for values, the
reason being to avoid synchronization upon usage. If we were to lazyload
them we'd have to put a synchronization thingy in all calls, which would
impact performance quite a lot.
The main issue is that you want to do role lookup using injection, if I
understand it correctly. Due to the eagerloading, which would also mess
things up if you have loads of roles on a value as it would
unnecessarily eagerload lots of unused roles, I don't think this is
really possible.
There is another way entirely to do these things though, which is to use
a generic mixin that delegates to another object. We used to have this
in Qi4j, and I'm not really sure where it went (Niclas, do you know?).
Basically you would have a mixin like this:
public class DelegatingMixin
implements InvocationHandler
{
@Uses Object delegate;
public Object invoke(Object proxy, Method method, Object[] args)
{
return method.invoke(delegate, args);
}
}
---
Then use this in a TransientComposite (not Value), and have the roles
"use it" by doing "@This SomeDataInterface data;" injections. That
should work.
/Rickard
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev