Note that there are some explanatory texts on larger screens.

plurals
  1. POgrails service hierarchy
    primarykey
    data
    text
    <p>Let's say I have 10 grails services. Each one of these services will be making calls to a REST service. So, I'd like to encapsulate the REST code so it can be easily resused by the 10 services.</p> <p>In considering options, I could:</p> <p>1) create another service or bean with REST related code and inject it every one of the 10 services.<br> 2) create a superclass service containing the REST code and have all 10 grails services extend this class.</p> <p>I'm trying to go with option 2, but running into problems with dependency injection into the superclass.</p> <p>Example:</p> <pre><code>class SuperService { def aString } class ExampleService extends SuperService { } </code></pre> <p>resources.groovy:</p> <pre><code>beans = { superService(SuperService) { aString = "something" } exampleService(ExampleService) { } } </code></pre> <p>When I run this in an debugger while running an integration test, I see the value of aString is null. Obviously, that's going to be problematic for me.</p> <p>As you might expect, running the same code with following resources.groovy:</p> <pre><code>beans = { superService(SuperService) { } exampleService(ExampleService) { aString = "something" } } </code></pre> <p>and aString = "something". </p> <p>So, I prefer option 2 because it will be less configuration wiring, but I don't think it's going to be feasible approach. In other words, there's no value if I have to set aString in each one of the subclasses.</p> <p>Thoughts?</p> <p>Am I missing something?</p> <p>I'm open to other options as well.</p> <p>Thanks in advance, Todd</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload