You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by daniel joyce <da...@gmail.com> on 2009/04/29 19:56:54 UTC

Injection and non-component non-service classes?

Is there any way to have a non-component class work with injection,
w/o having to turn it into a service itself?

@Inject
private SystemProperties sysProps;

I have a class that simply zips up files, and it needs access to a
system properties service. IIRC, but when I tried this in the past, it
didn't work for classes that were not pages/components. I also don't
want to necessarily turn a class into a service merely to give it
access to another service.

Any way to do this? Or was I simply doing it wrong before?

-Daniel

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


Re: Injection and non-component non-service classes?

Posted by Piero Sartini <ps...@sartini-its.com>.
I am using a small helper class to Inject Services into my not-managed domain 
objects:

public class Service {

	private static final Registry registry = IOCUtilities.buildDefaultRegistry();

	public static <T> T get(Class<T> clazz) {
		return registry.getService(clazz);
	}
}


	Piero

On Mittwoch, 29. April 2009 21:10:45 daniel joyce wrote:
> So basically once I start using Injection, every class that uses a
> injected class needs to be injected itself.
>
> It would be nice if this could be improved upon, thus allowing
> 'services' and non-page, non-service business objects to play nicely
> together.
>
> -Daniel


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


Re: Injection and non-component non-service classes?

Posted by daniel joyce <da...@gmail.com>.
Something like "DecorateTransactionally" that could be used to tell
Tapestry IOC which classes are using injected fields, and do the
injection/instrumentation on them.

On Wed, Apr 29, 2009 at 12:10 PM, daniel joyce <da...@gmail.com> wrote:
> So basically once I start using Injection, every class that uses a
> injected class needs to be injected itself.
>
> It would be nice if this could be improved upon, thus allowing
> 'services' and non-page, non-service business objects to play nicely
> together.
>
> -Daniel
>
> On Wed, Apr 29, 2009 at 11:39 AM, Howard Lewis Ship <hl...@gmail.com> wrote:
>> There isn't a mechanism for doing this via new C().  Tapestry IoC is
>> less intrusive than tapestry-core, it doesn't instrument your code the
>> way the web framework does, but it will use reflection to inject into
>> private fields.
>>
>> @Autobuild always creates a new instance.
>>
>>
>> On Wed, Apr 29, 2009 at 11:27 AM, daniel joyce <da...@gmail.com> wrote:
>>> I have a class C, that is not a service, nor a page/component
>>>
>>> I want to Inject a resource into it
>>>
>>> @Inject
>>> SomeService service
>>>
>>> When I use "new C()", I want them to be seperate instances, not
>>> singletons, or per-thread singletons, with that service wired in.
>>>
>>> Will what you posted do this?
>>>
>>> Because when I hear "Autobuild", my understanding is it generates
>>> singletons. But there is no guarantee this class C which is using
>>> SomeService is itself written to be a threadsafe singleton.
>>>
>>>
>>> On Wed, Apr 29, 2009 at 11:19 AM, Howard Lewis Ship <hl...@gmail.com> wrote:
>>>> In the following scenario:
>>>>
>>>> public void contributeMyConfiguration(Configuration<Foo>
>>>> configuration, @Autobuild FooImpl foo)
>>>> {
>>>>  configuration.add(foo);
>>>> }
>>>>
>>>> Tapestry will autobuild foo using the same rules as services.  Another approach:
>>>>
>>>> public void contributeMyConfiguration(Configuration<Foo> configuration)
>>>> {
>>>>  configuration.addInstance(FooImpl.class);
>>>> }
>>>>
>>>> This is an alternate way to inject an autobuild instance of the class.
>>>>
>>>>
>>>> On Wed, Apr 29, 2009 at 10:56 AM, daniel joyce <da...@gmail.com> wrote:
>>>>> Is there any way to have a non-component class work with injection,
>>>>> w/o having to turn it into a service itself?
>>>>>
>>>>> @Inject
>>>>> private SystemProperties sysProps;
>>>>>
>>>>> I have a class that simply zips up files, and it needs access to a
>>>>> system properties service. IIRC, but when I tried this in the past, it
>>>>> didn't work for classes that were not pages/components. I also don't
>>>>> want to necessarily turn a class into a service merely to give it
>>>>> access to another service.
>>>>>
>>>>> Any way to do this? Or was I simply doing it wrong before?
>>>>>
>>>>> -Daniel
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Howard M. Lewis Ship
>>>>
>>>> Creator of Apache Tapestry
>>>> Director of Open Source Technology at Formos
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>>
>>>
>>
>>
>>
>> --
>> Howard M. Lewis Ship
>>
>> Creator of Apache Tapestry
>> Director of Open Source Technology at Formos
>>
>> ---------------------------------------------------------------------
>> 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: Injection and non-component non-service classes?

Posted by daniel joyce <da...@gmail.com>.
IE, Class A is a service

Class B
@Inject
A a

Class C then uses Class B, but in order to access it, Class B must be
added to the appmodule via contrib config, and then class C needs

Class C
@Inject
B b

Then class D uses Class C, and it goes on and on. Once any class in
the chain uses a service, they all then need to be autobuilt in some
fashion, and you can't use new anymore. You can't break the chain as
it were, and mix constructors with autoinjected private fields.

It would be nice if you could go in your appmodule and say something like
@Match(A)
public static <T> T injectFields()

On Wed, Apr 29, 2009 at 12:10 PM, daniel joyce <da...@gmail.com> wrote:
> So basically once I start using Injection, every class that uses a
> injected class needs to be injected itself.
>
> It would be nice if this could be improved upon, thus allowing
> 'services' and non-page, non-service business objects to play nicely
> together.
>
> -Daniel

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


Re: Injection and non-component non-service classes?

Posted by daniel joyce <da...@gmail.com>.
So basically once I start using Injection, every class that uses a
injected class needs to be injected itself.

It would be nice if this could be improved upon, thus allowing
'services' and non-page, non-service business objects to play nicely
together.

-Daniel

On Wed, Apr 29, 2009 at 11:39 AM, Howard Lewis Ship <hl...@gmail.com> wrote:
> There isn't a mechanism for doing this via new C().  Tapestry IoC is
> less intrusive than tapestry-core, it doesn't instrument your code the
> way the web framework does, but it will use reflection to inject into
> private fields.
>
> @Autobuild always creates a new instance.
>
>
> On Wed, Apr 29, 2009 at 11:27 AM, daniel joyce <da...@gmail.com> wrote:
>> I have a class C, that is not a service, nor a page/component
>>
>> I want to Inject a resource into it
>>
>> @Inject
>> SomeService service
>>
>> When I use "new C()", I want them to be seperate instances, not
>> singletons, or per-thread singletons, with that service wired in.
>>
>> Will what you posted do this?
>>
>> Because when I hear "Autobuild", my understanding is it generates
>> singletons. But there is no guarantee this class C which is using
>> SomeService is itself written to be a threadsafe singleton.
>>
>>
>> On Wed, Apr 29, 2009 at 11:19 AM, Howard Lewis Ship <hl...@gmail.com> wrote:
>>> In the following scenario:
>>>
>>> public void contributeMyConfiguration(Configuration<Foo>
>>> configuration, @Autobuild FooImpl foo)
>>> {
>>>  configuration.add(foo);
>>> }
>>>
>>> Tapestry will autobuild foo using the same rules as services.  Another approach:
>>>
>>> public void contributeMyConfiguration(Configuration<Foo> configuration)
>>> {
>>>  configuration.addInstance(FooImpl.class);
>>> }
>>>
>>> This is an alternate way to inject an autobuild instance of the class.
>>>
>>>
>>> On Wed, Apr 29, 2009 at 10:56 AM, daniel joyce <da...@gmail.com> wrote:
>>>> Is there any way to have a non-component class work with injection,
>>>> w/o having to turn it into a service itself?
>>>>
>>>> @Inject
>>>> private SystemProperties sysProps;
>>>>
>>>> I have a class that simply zips up files, and it needs access to a
>>>> system properties service. IIRC, but when I tried this in the past, it
>>>> didn't work for classes that were not pages/components. I also don't
>>>> want to necessarily turn a class into a service merely to give it
>>>> access to another service.
>>>>
>>>> Any way to do this? Or was I simply doing it wrong before?
>>>>
>>>> -Daniel
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Howard M. Lewis Ship
>>>
>>> Creator of Apache Tapestry
>>> Director of Open Source Technology at Formos
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator of Apache Tapestry
> Director of Open Source Technology at Formos
>
> ---------------------------------------------------------------------
> 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: Injection and non-component non-service classes?

Posted by Howard Lewis Ship <hl...@gmail.com>.
There isn't a mechanism for doing this via new C().  Tapestry IoC is
less intrusive than tapestry-core, it doesn't instrument your code the
way the web framework does, but it will use reflection to inject into
private fields.

@Autobuild always creates a new instance.


On Wed, Apr 29, 2009 at 11:27 AM, daniel joyce <da...@gmail.com> wrote:
> I have a class C, that is not a service, nor a page/component
>
> I want to Inject a resource into it
>
> @Inject
> SomeService service
>
> When I use "new C()", I want them to be seperate instances, not
> singletons, or per-thread singletons, with that service wired in.
>
> Will what you posted do this?
>
> Because when I hear "Autobuild", my understanding is it generates
> singletons. But there is no guarantee this class C which is using
> SomeService is itself written to be a threadsafe singleton.
>
>
> On Wed, Apr 29, 2009 at 11:19 AM, Howard Lewis Ship <hl...@gmail.com> wrote:
>> In the following scenario:
>>
>> public void contributeMyConfiguration(Configuration<Foo>
>> configuration, @Autobuild FooImpl foo)
>> {
>>  configuration.add(foo);
>> }
>>
>> Tapestry will autobuild foo using the same rules as services.  Another approach:
>>
>> public void contributeMyConfiguration(Configuration<Foo> configuration)
>> {
>>  configuration.addInstance(FooImpl.class);
>> }
>>
>> This is an alternate way to inject an autobuild instance of the class.
>>
>>
>> On Wed, Apr 29, 2009 at 10:56 AM, daniel joyce <da...@gmail.com> wrote:
>>> Is there any way to have a non-component class work with injection,
>>> w/o having to turn it into a service itself?
>>>
>>> @Inject
>>> private SystemProperties sysProps;
>>>
>>> I have a class that simply zips up files, and it needs access to a
>>> system properties service. IIRC, but when I tried this in the past, it
>>> didn't work for classes that were not pages/components. I also don't
>>> want to necessarily turn a class into a service merely to give it
>>> access to another service.
>>>
>>> Any way to do this? Or was I simply doing it wrong before?
>>>
>>> -Daniel
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>
>>
>>
>> --
>> Howard M. Lewis Ship
>>
>> Creator of Apache Tapestry
>> Director of Open Source Technology at Formos
>>
>> ---------------------------------------------------------------------
>> 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
>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry
Director of Open Source Technology at Formos

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


Re: Injection and non-component non-service classes?

Posted by daniel joyce <da...@gmail.com>.
I have a class C, that is not a service, nor a page/component

I want to Inject a resource into it

@Inject
SomeService service

When I use "new C()", I want them to be seperate instances, not
singletons, or per-thread singletons, with that service wired in.

Will what you posted do this?

Because when I hear "Autobuild", my understanding is it generates
singletons. But there is no guarantee this class C which is using
SomeService is itself written to be a threadsafe singleton.


On Wed, Apr 29, 2009 at 11:19 AM, Howard Lewis Ship <hl...@gmail.com> wrote:
> In the following scenario:
>
> public void contributeMyConfiguration(Configuration<Foo>
> configuration, @Autobuild FooImpl foo)
> {
>  configuration.add(foo);
> }
>
> Tapestry will autobuild foo using the same rules as services.  Another approach:
>
> public void contributeMyConfiguration(Configuration<Foo> configuration)
> {
>  configuration.addInstance(FooImpl.class);
> }
>
> This is an alternate way to inject an autobuild instance of the class.
>
>
> On Wed, Apr 29, 2009 at 10:56 AM, daniel joyce <da...@gmail.com> wrote:
>> Is there any way to have a non-component class work with injection,
>> w/o having to turn it into a service itself?
>>
>> @Inject
>> private SystemProperties sysProps;
>>
>> I have a class that simply zips up files, and it needs access to a
>> system properties service. IIRC, but when I tried this in the past, it
>> didn't work for classes that were not pages/components. I also don't
>> want to necessarily turn a class into a service merely to give it
>> access to another service.
>>
>> Any way to do this? Or was I simply doing it wrong before?
>>
>> -Daniel
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator of Apache Tapestry
> Director of Open Source Technology at Formos
>
> ---------------------------------------------------------------------
> 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: Injection and non-component non-service classes?

Posted by Howard Lewis Ship <hl...@gmail.com>.
In the following scenario:

public void contributeMyConfiguration(Configuration<Foo>
configuration, @Autobuild FooImpl foo)
{
  configuration.add(foo);
}

Tapestry will autobuild foo using the same rules as services.  Another approach:

public void contributeMyConfiguration(Configuration<Foo> configuration)
{
  configuration.addInstance(FooImpl.class);
}

This is an alternate way to inject an autobuild instance of the class.


On Wed, Apr 29, 2009 at 10:56 AM, daniel joyce <da...@gmail.com> wrote:
> Is there any way to have a non-component class work with injection,
> w/o having to turn it into a service itself?
>
> @Inject
> private SystemProperties sysProps;
>
> I have a class that simply zips up files, and it needs access to a
> system properties service. IIRC, but when I tried this in the past, it
> didn't work for classes that were not pages/components. I also don't
> want to necessarily turn a class into a service merely to give it
> access to another service.
>
> Any way to do this? Or was I simply doing it wrong before?
>
> -Daniel
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry
Director of Open Source Technology at Formos

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