Hi,
On Jul 22, 2009, at 11:13 PM, Morten wrote:
> I have a question about how to inject Jersey-based artifacts with
> IoC managed artifacts and how to properly support javax's
> @Postconstruct. I.e. how to support injection and @Postconstruct to
> be fully supported for a mix of Jersey and a custom Ioc manged
> artifacts....I have something working partly as detailed below but
> have been unable to get constructor injection and @Postconstruct
> working fully.
>
> My situation is that I have a custom mini IvC framework that can
> inject non-jersey artifacts and I want to use this on jersey
> controllers besides the build-in jersey artifacts already supported
> by @Context.
>
> So far, I have sucessfully implemented a
> com.sun.jersey.core.spi.component.ioc.. IoCComponentProviderFactory.
> This factory delegates construction of our IvC resources to our own
> IvC framework using IoCManagedComponentProvider. We can thus create
> and inject our own Ivc artifacts without problem and jersey will
> follow up with injecting jersey artifacts into the controller fields
> once they are returned by our factory
>
> So far so good. Remaining problems are:
>
> 1) How to inject jersey artifacts into the constructor? The
> IoCFullyManagedComponentProvider javadoc notes that another factory
> "IoCComponentProcessorFactory" may be used for this purpose inside
> our factory, but how do we get hold of an instance of the class
> IoCComponentProcessorFactory ?
IoCComponentProcessorFactory will only work for field/method
injection. Plugable constructor injection is always problematic.
> 2) How to call @Postconstruct once Jersey has finished injecting its
> jersey artifacts? Currently, we do this at the end of our
> implementation of IoCComponentProviderFactory but this is too early
> as Jersey then has had no chance yet to inject it's artifacts yet
> (done by jersey after our factory returns the object).
>
>
Unfortunately it is currently not possible to support injection before
@PostConstruct.
You can use is IoCProxiedComponentProvider and in the proxy method
perform injection and then return the same instance. But the proxy
method will be called after @PostConstruct. The use of an
IoCProxiedComponentProvider means that Jersey will control the life-
cycle.
Does your IvC framework control the life-cycle (scope, post construct
and pre destroy) of the instantiated components ? or can you defer to
Jersey to do that ?
The answer to that question can help determine what sort of fix would
be required to support what you need.
For example, if the former then for each constructor parameter that
you cannot bind there will need to be a way to ask Jersey if it can.
If the latter then we need to interpose between instantiation and post
construction and allow third party injection.
Paul.