Thanks for the example. I think that will meet my needs. I don't think I
would have ever figured that out from the existing documentation.


On Mon, Sep 30, 2013 at 6:21 AM, Thiago H de Paula Figueiredo <
[email protected]> wrote:

> On Sat, 28 Sep 2013 11:20:21 -0300, Barry Books <[email protected]> wrote:
>
>  I think we are talking about two different things here or there is a
>> Tapestry feature I don't know about.
>>
>
> I'm not sure you tried to understand what I suggested you in my previous
> message.
>
>
>  I'm looking for a feature that will
>> return a new "Plain Old Object" from an Interface. A simple example:
>>
>> Map map = objectFactory.build(Map.class)**;
>>
>
> I already know what you wanted and you just confirmed it now. I just
> suggested you to, instead of creating a new service just for instantiating
> interfaces, to reuse ObjectProvider and MasterObjectProvider instead. They
> have a scope which is a little broader than what you want: give it a type
> and it'll return (or not) an object of that type. The only difference is
> that in your service the contribution can only provide one type, while an
> ObjectProvider can provide many.
>
> Here's one example:
>
> In a module class:
>
> public static void contributeMasterObjectProvider**(OrderedConfiguration<*
> *ObjectProvider> configuration) {
>         final ObjectProvider mapProvider = new ObjectProvider() {
>                 public <T> T provide(Class<T> objectType,
>                                 AnnotationProvider annotationProvider,
> ObjectLocator locator) {
>                         Object newObject = null;
>                         if (objectType == Map.class) {
>                                 newObject = new HashMap();
>                         }
>                         return (T) newObject;
>                 }
>         };
>         configuration.add("Map", mapProvider);
> }
>
> Now you can inject the MasterObjectProvider service, which is part of
> Tapestry-IoC, and use it this way to get a Map instance:
>
> Map map1 = masterObjectProvider.provide(**Map.class, null, null, true);
> Map map2 = masterObjectProvider.provide(**Map.class, null, null, true);
> // prints 'true' because each time you call MasterObjectProvider.provide()
> and your ObjectProvider is the one who returns
> // the instance, it returns a new one.
> System.out.println(map1 != map2);
>
> You can even @Inject Maps now!
>
> @Inject
> private Map map1;
>
> @Inject
> private Map map2;
>
> Object onActivate(EventContext context) {
>         System.out.println(map1 != map2); // prints 'true'
>         ...
> }
>
> So, in summary, I'm against Barry's suggestion because the ObjectProvider/
> **MasterObjectProvider dynamic duo already implements what you want and
> we would otherwise have two differents services to do the same thing.
>
>
> --
> Thiago H. de Paula Figueiredo
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: 
> dev-unsubscribe@tapestry.**apache.org<[email protected]>
> For additional commands, e-mail: [email protected]
>
>

Reply via email to