You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Kristian Marinkovic <kr...@porsche.co.at> on 2007/12/10 11:13:46 UTC

[T5] injecting services into Domain Objects

hi all,

is it possible to use tapestry-ioc to inject services into domain 
objects? i'm thinking of something like @Configurable in spring. 

when using (build-time) AOP i need a reference to the registry,
but how do i get it? preferably i'd assign the generated proxy 
to the fields. 

i'd appreciate any suggestions!

g,
kris

example code:
public class Order {
   @Inject Repository repository; 
   @Inject Notification notification; 
}

Re: [T5] injecting services into Domain Objects

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
I meant domain class, sorry.

Filip S. Adamsen skrev:
> Oh, I wasn't talking about sticking it in a class. That'd be... ugh. No.
> 
> I meant to have some class, presumably a singleton, hold the Registry. 
> But certainly not a domain object. Never. Ever.
> 
> -Filip
> 
> Paul Cooley skrev:
>> It's better to have a simple singleton factory to contain the registry.
>> Plus if you were crazy enough to put it into a domain object as a 
>> reference
>> (or any service reference) you need to make sure it's marked as 
>> transient so
>> it will be ignored when serialization occurs for the domain object.
>>
>> On Dec 10, 2007 1:40 PM, Filip S. Adamsen <fs...@fsadev.com> wrote:
>>
>>> Well, having a Registry instance in some class is what you would do if
>>> you were to run Tapestry 5 IoC as part of a non-web application.
>>>
>>> I guess you could subclass TapestryFilter and override the init method
>>> to get a hold of the Registry for retrieval through a static getter,
>>> although I'm not sure how clean that is and what, if any, the
>>> ramifications would be.
>>>
>>> -Filip
>>>
>>> jeffrey ai skrev:
>>>>> is it possible to use tapestry-ioc to inject services into domain
>>> objects?
>>>> First, I don't think it's good practice to inject services into domain
>>>> objects. If some operation of domain object really needs to use a
>>> service,
>>>> you could pass a service instance to that specific method instead of
>>>> injecting it.
>>>> To my understanding, Tapestry dependency injection is mainly for
>>> services.
>>>> You could inject a dependency as a parameter of the service builder
>>> method,
>>>> or as a parameter of the service implementation's constructor(for
>>> autobuilt
>>>> services),  or as a parameter of the module builder's constructor.
>>>>
>>>>> when using (build-time) AOP i need a reference to the registry, but 
>>>>> how
>>> do
>>>>> i get it?
>>>> The default Tapestry application registry is created in TapestryFilter,
>>> and
>>>> I don't see it's published out.
>>>> You could of course create your own registry using RegistryBuilder and
>>>> publish it somehow,  but I don't think that's a good practice to have a
>>>> registry in your class and  retrieve services from it.
>>>>
>>>> Cheers,
>>>> Jeffrey Ai
>>>>
>>>>
>>>> kristian.marinkovic wrote:
>>>>> hi all,
>>>>>
>>>>> is it possible to use tapestry-ioc to inject services into domain
>>>>> objects? i'm thinking of something like @Configurable in spring.
>>>>>
>>>>> when using (build-time) AOP i need a reference to the registry,
>>>>> but how do i get it? preferably i'd assign the generated proxy
>>>>> to the fields.
>>>>>
>>>>> i'd appreciate any suggestions!
>>>>>
>>>>> g,
>>>>> kris
>>>>>
>>>>> example code:
>>>>> public class Order {
>>>>>    @Inject Repository repository;
>>>>>    @Inject Notification notification;
>>>>> }
>>>>>
>>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] injecting services into Domain Objects

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Oh, I wasn't talking about sticking it in a class. That'd be... ugh. No.

I meant to have some class, presumably a singleton, hold the Registry. 
But certainly not a domain object. Never. Ever.

-Filip

Paul Cooley skrev:
> It's better to have a simple singleton factory to contain the registry.
> Plus if you were crazy enough to put it into a domain object as a reference
> (or any service reference) you need to make sure it's marked as transient so
> it will be ignored when serialization occurs for the domain object.
> 
> On Dec 10, 2007 1:40 PM, Filip S. Adamsen <fs...@fsadev.com> wrote:
> 
>> Well, having a Registry instance in some class is what you would do if
>> you were to run Tapestry 5 IoC as part of a non-web application.
>>
>> I guess you could subclass TapestryFilter and override the init method
>> to get a hold of the Registry for retrieval through a static getter,
>> although I'm not sure how clean that is and what, if any, the
>> ramifications would be.
>>
>> -Filip
>>
>> jeffrey ai skrev:
>>>> is it possible to use tapestry-ioc to inject services into domain
>> objects?
>>> First, I don't think it's good practice to inject services into domain
>>> objects. If some operation of domain object really needs to use a
>> service,
>>> you could pass a service instance to that specific method instead of
>>> injecting it.
>>> To my understanding, Tapestry dependency injection is mainly for
>> services.
>>> You could inject a dependency as a parameter of the service builder
>> method,
>>> or as a parameter of the service implementation's constructor(for
>> autobuilt
>>> services),  or as a parameter of the module builder's constructor.
>>>
>>>> when using (build-time) AOP i need a reference to the registry, but how
>> do
>>>> i get it?
>>> The default Tapestry application registry is created in TapestryFilter,
>> and
>>> I don't see it's published out.
>>> You could of course create your own registry using RegistryBuilder and
>>> publish it somehow,  but I don't think that's a good practice to have a
>>> registry in your class and  retrieve services from it.
>>>
>>> Cheers,
>>> Jeffrey Ai
>>>
>>>
>>> kristian.marinkovic wrote:
>>>> hi all,
>>>>
>>>> is it possible to use tapestry-ioc to inject services into domain
>>>> objects? i'm thinking of something like @Configurable in spring.
>>>>
>>>> when using (build-time) AOP i need a reference to the registry,
>>>> but how do i get it? preferably i'd assign the generated proxy
>>>> to the fields.
>>>>
>>>> i'd appreciate any suggestions!
>>>>
>>>> g,
>>>> kris
>>>>
>>>> example code:
>>>> public class Order {
>>>>    @Inject Repository repository;
>>>>    @Inject Notification notification;
>>>> }
>>>>
>>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] injecting services into Domain Objects

Posted by Paul Cooley <pe...@gmail.com>.
It's better to have a simple singleton factory to contain the registry.
Plus if you were crazy enough to put it into a domain object as a reference
(or any service reference) you need to make sure it's marked as transient so
it will be ignored when serialization occurs for the domain object.

On Dec 10, 2007 1:40 PM, Filip S. Adamsen <fs...@fsadev.com> wrote:

> Well, having a Registry instance in some class is what you would do if
> you were to run Tapestry 5 IoC as part of a non-web application.
>
> I guess you could subclass TapestryFilter and override the init method
> to get a hold of the Registry for retrieval through a static getter,
> although I'm not sure how clean that is and what, if any, the
> ramifications would be.
>
> -Filip
>
> jeffrey ai skrev:
> >> is it possible to use tapestry-ioc to inject services into domain
> objects?
> > First, I don't think it's good practice to inject services into domain
> > objects. If some operation of domain object really needs to use a
> service,
> > you could pass a service instance to that specific method instead of
> > injecting it.
> > To my understanding, Tapestry dependency injection is mainly for
> services.
> > You could inject a dependency as a parameter of the service builder
> method,
> > or as a parameter of the service implementation's constructor(for
> autobuilt
> > services),  or as a parameter of the module builder's constructor.
> >
> >> when using (build-time) AOP i need a reference to the registry, but how
> do
> >> i get it?
> > The default Tapestry application registry is created in TapestryFilter,
> and
> > I don't see it's published out.
> > You could of course create your own registry using RegistryBuilder and
> > publish it somehow,  but I don't think that's a good practice to have a
> > registry in your class and  retrieve services from it.
> >
> > Cheers,
> > Jeffrey Ai
> >
> >
> > kristian.marinkovic wrote:
> >> hi all,
> >>
> >> is it possible to use tapestry-ioc to inject services into domain
> >> objects? i'm thinking of something like @Configurable in spring.
> >>
> >> when using (build-time) AOP i need a reference to the registry,
> >> but how do i get it? preferably i'd assign the generated proxy
> >> to the fields.
> >>
> >> i'd appreciate any suggestions!
> >>
> >> g,
> >> kris
> >>
> >> example code:
> >> public class Order {
> >>    @Inject Repository repository;
> >>    @Inject Notification notification;
> >> }
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Gotta find my destiny, before it gets too late.-- Ian Curtis

Re: [T5] injecting services into Domain Objects

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Well, having a Registry instance in some class is what you would do if 
you were to run Tapestry 5 IoC as part of a non-web application.

I guess you could subclass TapestryFilter and override the init method 
to get a hold of the Registry for retrieval through a static getter, 
although I'm not sure how clean that is and what, if any, the 
ramifications would be.

-Filip

jeffrey ai skrev:
>> is it possible to use tapestry-ioc to inject services into domain objects?
> First, I don't think it's good practice to inject services into domain
> objects. If some operation of domain object really needs to use a service,
> you could pass a service instance to that specific method instead of
> injecting it.
> To my understanding, Tapestry dependency injection is mainly for services.
> You could inject a dependency as a parameter of the service builder method,
> or as a parameter of the service implementation's constructor(for autobuilt
> services),  or as a parameter of the module builder's constructor.
> 
>> when using (build-time) AOP i need a reference to the registry, but how do
>> i get it? 
> The default Tapestry application registry is created in TapestryFilter, and
> I don't see it's published out.
> You could of course create your own registry using RegistryBuilder and
> publish it somehow,  but I don't think that's a good practice to have a
> registry in your class and  retrieve services from it.
> 
> Cheers,
> Jeffrey Ai
> 
> 
> kristian.marinkovic wrote:
>> hi all,
>>
>> is it possible to use tapestry-ioc to inject services into domain 
>> objects? i'm thinking of something like @Configurable in spring. 
>>
>> when using (build-time) AOP i need a reference to the registry,
>> but how do i get it? preferably i'd assign the generated proxy 
>> to the fields. 
>>
>> i'd appreciate any suggestions!
>>
>> g,
>> kris
>>
>> example code:
>> public class Order {
>>    @Inject Repository repository; 
>>    @Inject Notification notification; 
>> }
>>
>>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] injecting services into Domain Objects

Posted by jeffrey ai <jf...@gmail.com>.
> is it possible to use tapestry-ioc to inject services into domain objects?
First, I don't think it's good practice to inject services into domain
objects. If some operation of domain object really needs to use a service,
you could pass a service instance to that specific method instead of
injecting it.
To my understanding, Tapestry dependency injection is mainly for services.
You could inject a dependency as a parameter of the service builder method,
or as a parameter of the service implementation's constructor(for autobuilt
services),  or as a parameter of the module builder's constructor.

> when using (build-time) AOP i need a reference to the registry, but how do
> i get it? 
The default Tapestry application registry is created in TapestryFilter, and
I don't see it's published out.
You could of course create your own registry using RegistryBuilder and
publish it somehow,  but I don't think that's a good practice to have a
registry in your class and  retrieve services from it.

Cheers,
Jeffrey Ai


kristian.marinkovic wrote:
> 
> hi all,
> 
> is it possible to use tapestry-ioc to inject services into domain 
> objects? i'm thinking of something like @Configurable in spring. 
> 
> when using (build-time) AOP i need a reference to the registry,
> but how do i get it? preferably i'd assign the generated proxy 
> to the fields. 
> 
> i'd appreciate any suggestions!
> 
> g,
> kris
> 
> example code:
> public class Order {
>    @Inject Repository repository; 
>    @Inject Notification notification; 
> }
> 
> 

-- 
View this message in context: http://www.nabble.com/-T5--injecting-services-into-Domain-Objects-tp14250305p14258571.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] injecting services into Domain Objects

Posted by jeffrey ai <jf...@gmail.com>.
> as pointed out by jeffrey i could also pass in the services as needed
> but i think this approach will bloat the methods of my domain objects.
> have you used this approach on a big codebase? doesn't it have some
> negative effects on the expressiveness of the Domain Objects?

When some domain logic need to use some service, I think there are 3 ways to
get that service :

* passed as parameter
* injected into domain object
* pulled the service out from some registry in a method

To my humble opinion, "passed as parameter" is the most clean way to make
domain object reusable. 
For example, if you have an Order domain object, needs a TaxCaculator
service in some method.  You could pass either a USATaxCaculator or
CanadaTaxCaculator in.  The other ways don't provide this flexibility. 

Only if you are sure that a service will only have one implementation in
your system for domain object use, you  might  choose the 2nd or the 3rd
way. In this case, I am favoring the 3rd way.

P.S. 
We have used the combination of 1st and 3rd way in a medium-scale e-commerce
software.

Cheers,
Jeffrey Ai


-- 
View this message in context: http://www.nabble.com/-T5--injecting-services-into-Domain-Objects-tp14250305p14279147.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org