mehandih / grails-jaxrs

Automatically exported from code.google.com/p/grails-jaxrs
0 stars 0 forks source link

Depedency injection doesn't work with generate-resources #43

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Depedency injection doesn't work with generate-resources. I didnt search much 
about why but it seems that the pattern ResourceCollection/resource brake it. 
If you only make a one Resource class it will get injected.

What version of the product are you using? On what operating system?
0.4 and 0.5

Original issue reported on code.google.com by stest...@gmail.com on 5 Aug 2011 at 1:11

GoogleCodeExporter commented 8 years ago
May I ask why do you want to DI resource class instances somewhere? Or do I get 
that wrong? Resources should only be accessed by the JAX-RS runtime.

Original comment by krass...@googlemail.com on 5 Aug 2011 at 5:22

GoogleCodeExporter commented 8 years ago
Or do you mean something like 
http://code.google.com/p/grails-jaxrs/wiki/AdvancedFeatures#Service_injection 
for generated resources?

Original comment by krass...@googlemail.com on 5 Aug 2011 at 5:40

GoogleCodeExporter commented 8 years ago
exactly what i meant yes, the service won't get injected if
ResourceCollection instanciate Resource

Original comment by stest...@gmail.com on 5 Aug 2011 at 5:54

GoogleCodeExporter commented 8 years ago
Ah ok. Will take a look.

Original comment by krass...@googlemail.com on 5 Aug 2011 at 6:14

GoogleCodeExporter commented 8 years ago
In generated resources, I plan to delegate all CRUD actions to a (generated) 
service class. The generated service is then used by the Resource and 
ResourceCollection classes. This means that the actual CRUD work is done inside 
service methods which allows better control over transaction boundaries and you 
can also inject any additional dependencies into that service. 

Would this fit your needs?

Alternatively, you can still autowire dependencies into CollectionResource 
classes and pass them as arguments to the Resource constructor if you want 
(which requires a little modification to the generated code though).

Original comment by krass...@googlemail.com on 28 Aug 2011 at 7:08

GoogleCodeExporter commented 8 years ago
An example how to do programmatic dependency injection with Grails is described 
at 
http://stackoverflow.com/questions/1675399/grails-dependency-injection-in-regula
r-groovy-class, for example

Original comment by krass...@googlemail.com on 28 Aug 2011 at 7:20

GoogleCodeExporter commented 8 years ago
That would be perfect, right now i just use one resource class and
everything work well

Original comment by stest...@gmail.com on 29 Aug 2011 at 12:57

GoogleCodeExporter commented 8 years ago
This is now implemented with the that commit on master: 
https://github.com/krasserm/grails-jaxrs/commit/955c77be0ba17fd2ba5e75028e9a0be6
f63a265b.

Original comment by krass...@googlemail.com on 30 Aug 2011 at 9:15