Hi Jerome,
Jerome Louvel <contact <at> noelios.com> writes:
>
> Hi all,
>
> Thanks for exploring this recurring issue. I realize that the current
> approach isn't flexible enough in many case. So, I have restored the default
> constructor and added a new 'init(Context, Request, Response) method that
> gets invoke by the other constructor.
This clearly adds much needed flexibility. Thanks.
> Also, the Finder class will now look for a default constructor if the normal
> one isn't available and will call 'init' after the instantiation in this
> case. This should make everyone happy.
I can't decide if I'm happy based on the description of the change. I am
unclear how this helps my issue. I have application level state the
resource requires.
I don't see how the above changes resolve that issue.
One solution would be to add Finder(Context context, ResourceFactory factory).
interface ResourceFactory {
public Resource createResource(Class<? extends Resource> targetClass);
}
That would allow me to say something like:
public class MyApplication extends Application implements ResourceFactory {
private State state = ...
...
public Resource createResource(Class<? extends Resource> targetClass) {
// Create the targetClass and initialize it with my state.
...
return r;
}
Then in Finder, the factory gets called to create an instance that I can
initialize. Then finder calls Resource.init(...).
I'm not sure if this is the best solution but hopefully it makes clear
the capability I'm interested in.
Sean