You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by manuel aldana <al...@gmx.de> on 2009/04/20 21:42:23 UTC
[tap-ioc] passing a set of autobuild types to bind()
Hi,
I am injecting services to my domain model classes. For that I am using
the ServiceBinder.bind(implementationClass). This is kind of repetitive
if I want to add all classes of a certain package.
Is it somehow possible to add a set of class at once to autobuild
control, for instance by passing a package identifier?
--
manuel aldana
aldana@gmx.de
software-engineering blog: http://www.aldana-online.de
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [tap-ioc] passing a set of autobuild types to bind()
Posted by manuel aldana <al...@gmx.de>.
OK, here an example:
A User is encapsulating password details. It gets a plain-text as input
is taking security actions internally. Because I want to extract
security implementation details (encryption/hashing) from the domain
model I want to end up with an injectable security instance. Still
things should be handled from the domain object.
class User{
...
//provides security actions on a string input, password should not be
kept as plaintext
@Inject PasswordEncoder
...
//one use case to have the password knowledge
public boolean isEligible(String password){...}
}
I know I could handle all this password stuff outside of the User (e.g.
AuthentcationService). This is also dependant how it technically fits to
a used security framework (authorize/authenticate). With this example I
just wanted to show that it can make sense to inject services to a
domain-object.
I hope you can see my motivation why I want to add a set of classes by
package name into SerivceBinder.bind(). E.g. autobuild all my
domain-object from a model package.
Christian Edward Gruber schrieb:
> Oh, sorry - ServiceBinder... I was thinking you were injecting a
> service lookup object into your model - I was clearly too brain-dead
> and didn't read it properly.
>
> So, you're binding services in modules and injecting them with @Inject
> - that's fine, so far. But I don't understand, then, how you're
> injecting things into value objects? That just doesn't make sense to
> me. Can you provide a cleansed example?
>
> Christian.
>
> On 21-Apr-09, at 06:49 , manuel aldana wrote:
>
>> I don't see a problem here. I am having dependencies on interface
>> level which should be fine. For testability I can just inject a
>> test-implementation of this interface. I don't see a strong coupling
>> to the container in my model (apart from the @Inject annotation).
>>
>> Christian Edward Gruber wrote:
>>> Are your model classes their own controllers? If you're doing what
>>> you describe, then you're tightly coupling your model classes to the
>>> implementation of the application. It's not forbidden or anything,
>>> but it's often not considered best practice (though as with all good
>>> practice, there are notable exceptions, so I don't want to judge
>>> hastily). But I typically consider this a DI/IoC anti-pattern -
>>> injecting the container itself or statically binding the container
>>> (via ServiceBinder) into domain objects. Makes things hard to test,
>>> hard to disentangle, and really really hard to port later.
>>>
>>> Christian.
>>>
>>> On 20-Apr-09, at 15:42 , manuel aldana wrote:
>>>
>>>> Hi,
>>>>
>>>> I am injecting services to my domain model classes. For that I am
>>>> using the ServiceBinder.bind(implementationClass). This is kind of
>>>> repetitive if I want to add all classes of a certain package.
>>>>
>>>> Is it somehow possible to add a set of class at once to autobuild
>>>> control, for instance by passing a package identifier?
>>>>
>>>> --
>>>> manuel aldana
>>>> aldana@gmx.de
>>>> software-engineering blog: http://www.aldana-online.de
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>
>>>
>>> Christian Edward Gruber
>>> e-mail: christianedwardgruber@gmail.com
>>> weblog: http://www.geekinasuit.com/
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>
> Christian Edward Gruber
> e-mail: christianedwardgruber@gmail.com
> weblog: http://www.geekinasuit.com/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
--
manuel aldana
aldana@gmx.de
software-engineering blog: http://www.aldana-online.de
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [tap-ioc] passing a set of autobuild types to bind()
Posted by Christian Edward Gruber <ch...@gmail.com>.
Oh, sorry - ServiceBinder... I was thinking you were injecting a
service lookup object into your model - I was clearly too brain-dead
and didn't read it properly.
So, you're binding services in modules and injecting them with @Inject
- that's fine, so far. But I don't understand, then, how you're
injecting things into value objects? That just doesn't make sense to
me. Can you provide a cleansed example?
Christian.
On 21-Apr-09, at 06:49 , manuel aldana wrote:
> I don't see a problem here. I am having dependencies on interface
> level which should be fine. For testability I can just inject a test-
> implementation of this interface. I don't see a strong coupling to
> the container in my model (apart from the @Inject annotation).
>
> Christian Edward Gruber wrote:
>> Are your model classes their own controllers? If you're doing what
>> you describe, then you're tightly coupling your model classes to
>> the implementation of the application. It's not forbidden or
>> anything, but it's often not considered best practice (though as
>> with all good practice, there are notable exceptions, so I don't
>> want to judge hastily). But I typically consider this a DI/IoC
>> anti-pattern - injecting the container itself or statically binding
>> the container (via ServiceBinder) into domain objects. Makes
>> things hard to test, hard to disentangle, and really really hard to
>> port later.
>>
>> Christian.
>>
>> On 20-Apr-09, at 15:42 , manuel aldana wrote:
>>
>>> Hi,
>>>
>>> I am injecting services to my domain model classes. For that I am
>>> using the ServiceBinder.bind(implementationClass). This is kind of
>>> repetitive if I want to add all classes of a certain package.
>>>
>>> Is it somehow possible to add a set of class at once to autobuild
>>> control, for instance by passing a package identifier?
>>>
>>> --
>>> manuel aldana
>>> aldana@gmx.de
>>> software-engineering blog: http://www.aldana-online.de
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>
>> Christian Edward Gruber
>> e-mail: christianedwardgruber@gmail.com
>> weblog: http://www.geekinasuit.com/
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
Christian Edward Gruber
e-mail: christianedwardgruber@gmail.com
weblog: http://www.geekinasuit.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [tap-ioc] passing a set of autobuild types to bind()
Posted by manuel aldana <al...@gmx.de>.
I don't see a problem here. I am having dependencies on interface level
which should be fine. For testability I can just inject a
test-implementation of this interface. I don't see a strong coupling to
the container in my model (apart from the @Inject annotation).
Christian Edward Gruber wrote:
> Are your model classes their own controllers? If you're doing what
> you describe, then you're tightly coupling your model classes to the
> implementation of the application. It's not forbidden or anything,
> but it's often not considered best practice (though as with all good
> practice, there are notable exceptions, so I don't want to judge
> hastily). But I typically consider this a DI/IoC anti-pattern -
> injecting the container itself or statically binding the container
> (via ServiceBinder) into domain objects. Makes things hard to test,
> hard to disentangle, and really really hard to port later.
>
> Christian.
>
> On 20-Apr-09, at 15:42 , manuel aldana wrote:
>
>> Hi,
>>
>> I am injecting services to my domain model classes. For that I am
>> using the ServiceBinder.bind(implementationClass). This is kind of
>> repetitive if I want to add all classes of a certain package.
>>
>> Is it somehow possible to add a set of class at once to autobuild
>> control, for instance by passing a package identifier?
>>
>> --
>> manuel aldana
>> aldana@gmx.de
>> software-engineering blog: http://www.aldana-online.de
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
> Christian Edward Gruber
> e-mail: christianedwardgruber@gmail.com
> weblog: http://www.geekinasuit.com/
>
>
> ---------------------------------------------------------------------
> 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: [tap-ioc] passing a set of autobuild types to bind()
Posted by Christian Edward Gruber <ch...@gmail.com>.
Are your model classes their own controllers? If you're doing what
you describe, then you're tightly coupling your model classes to the
implementation of the application. It's not forbidden or anything,
but it's often not considered best practice (though as with all good
practice, there are notable exceptions, so I don't want to judge
hastily). But I typically consider this a DI/IoC anti-pattern -
injecting the container itself or statically binding the container
(via ServiceBinder) into domain objects. Makes things hard to test,
hard to disentangle, and really really hard to port later.
Christian.
On 20-Apr-09, at 15:42 , manuel aldana wrote:
> Hi,
>
> I am injecting services to my domain model classes. For that I am
> using the ServiceBinder.bind(implementationClass). This is kind of
> repetitive if I want to add all classes of a certain package.
>
> Is it somehow possible to add a set of class at once to autobuild
> control, for instance by passing a package identifier?
>
> --
> manuel aldana
> aldana@gmx.de
> software-engineering blog: http://www.aldana-online.de
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
Christian Edward Gruber
e-mail: christianedwardgruber@gmail.com
weblog: http://www.geekinasuit.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [tap-ioc] passing a set of autobuild types to bind()
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 20 Apr 2009 19:11:24 -0300, manuel aldana <al...@gmx.de> escreveu:
> but would be cool if there was something like:
>
> //add all classes from services package into autobuild set
> binder.bind("org.foo.bar.services.*");
It would :), but it's quite easy to write a class with a static method
that does this using ClassNameLocator(Impl). If you search this listt
archives, you'll find me and other people (including Howard) discussing
services autobinding.
--
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [tap-ioc] passing a set of autobuild types to bind()
Posted by manuel aldana <al...@gmx.de>.
Thiago H. de Paula Figueiredo schrieb:
> Em Mon, 20 Apr 2009 16:42:23 -0300, manuel aldana <al...@gmx.de>
> escreveu:
>
>> Hi,
>>
>> I am injecting services to my domain model classes. For that I am
>> using the ServiceBinder.bind(implementationClass). This is kind of
>> repetitive if I want to add all classes of a certain package.
>>
>> Is it somehow possible to add a set of class at once to autobuild
>> control, for instance by passing a package identifier?
>
> Use the ClassNameLocator service to find all classes inside a package
> them loop the results. Inside a module bind() method, you'll need to
> instantiate ClassNameLocatorImpl yourself, as Tapestry does not do
> service injection in this method.
I see. thanks.
but would be cool if there was something like:
//add all classes from services package into autobuild set
binder.bind("org.foo.bar.services.*");
--
manuel aldana
aldana@gmx.de
software-engineering blog: http://www.aldana-online.de
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [tap-ioc] passing a set of autobuild types to bind()
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 20 Apr 2009 16:42:23 -0300, manuel aldana <al...@gmx.de> escreveu:
> Hi,
>
> I am injecting services to my domain model classes. For that I am using
> the ServiceBinder.bind(implementationClass). This is kind of repetitive
> if I want to add all classes of a certain package.
>
> Is it somehow possible to add a set of class at once to autobuild
> control, for instance by passing a package identifier?
Use the ClassNameLocator service to find all classes inside a package them
loop the results. Inside a module bind() method, you'll need to
instantiate ClassNameLocatorImpl yourself, as Tapestry does not do service
injection in this method.
--
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org