Fornax-Platform
Forum

Injection of Service from other Module doesn't work?

View: New views
3 Messages — Rating Filter:   Alert me  

Injection of Service from other Module doesn't work?

by Bjoern_G :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I can't get Services from other Modules injected, any ideas what could be wrong? The Service I want to inject is not generated into the ServiceBaseImpl, and it also doesn't show up in the Services-....xml (so the problem is not that I should provide the setter myself, as for "external" services).

I have tried it several times with different services.

using > @ServiceName as usual.

Re: Injection of Service from other Module doesn't work?

by Patrik Nordwall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Right now you can only inject repositories and external beans, not other services.
http://www.fornax-platform.org/tracker/browse/CSC-189

However, the workaround is easy (but ugly).
Add a method that delegates to the service. It can be protected to avoid visibility in public api.

        Service PlanetService {
            protected injectionDummy => @AnotherService.dummy;
            String sayHello(String planetName) throws PlanetNotFoundException;
            protected findByExample => PlanetRepository.findByExample;
            @Planet getPlanet(String planetName) throws PlanetNotFoundException;
        }

        Service AnotherService {
                void dummy();
        }

/Patrik

Bjoern_G wrote:
I can't get Services from other Modules injected, any ideas what could be wrong? The Service I want to inject is not generated into the ServiceBaseImpl, and it also doesn't show up in the Services-....xml (so the problem is not that I should provide the setter myself, as for "external" services).

I have tried it several times with different services.

using > @ServiceName as usual.

Re: Injection of Service from other Module doesn't work?

by Bjoern_G :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks! I also just found another workaround: pretend the service is an "external service", that is, write

> planetService instead of > @PlanetService

Then I can provide my own setter and it works.

Patrik Nordwall wrote:
Right now you can only inject repositories and external beans, not other services.
http://www.fornax-platform.org/tracker/browse/CSC-189

However, the workaround is easy (but ugly).
Add a method that delegates to the service. It can be protected to avoid visibility in public api.

        Service PlanetService {
            protected injectionDummy => @AnotherService.dummy;
            String sayHello(String planetName) throws PlanetNotFoundException;
            protected findByExample => PlanetRepository.findByExample;
            @Planet getPlanet(String planetName) throws PlanetNotFoundException;
        }

        Service AnotherService {
                void dummy();
        }

/Patrik

I can't get Services from other Modules injected, any ideas what could be wrong? The Service I want to inject is not generated into the ServiceBaseImpl, and it also doesn't show up in the Services-....xml (so the problem is not that I should provide the setter myself, as for "external" services).

I have tried it several times with different services.

using > @ServiceName as usual.



LightInTheBox - Buy quality products at wholesale price