Hi Sam.

    I wanted something along these lines:

1. When creating new resources, no URI is given. The resource is populated, save() is invoked, and at that time a URI is set on the resource. 2. When loading existing resources, a URI is supplied are construction time and is used to load the resource state.

Having worked further through this example I realized that create(), load(), save() didn't really belong in the resource class. By moving them into a separate factory class I avoided the need for AssistedInject altogether. I guess the point is that as factories get more sophisticated it makes sense to code them by hand.

Thanks,
Gili

On 20/06/2011 1:57 PM, Sam Berlin wrote:
What is it that you're trying to achieve here? Do you have a Factory interface for creating Resource? Are you expecting the Factory method to always supply a URI? Or sometimes not supply it? Or supply it but let it be null?

sam

On Sun, Jun 19, 2011 at 10:58 PM, cowwoc <[email protected] <mailto:[email protected]>> wrote:

    Hi,

    How can I mix optional parameters into a constructor with
    AssistedInject? For example:

    public class Resource
    {
     @Inject
     public Resource(@Assisted URI uri, Helper helper)
     {...}

     public static interface Builder
     {
       /**
        * Create a new resource (uri is null).
        */
       Resource create();

       /**
        * Load an existing resource (uri is non-null).
        */
       Resource load(URI uri);
     }
    }

    I tried this:

    public class Resource
    {
     @Inject
     public Resource(UriHolder uri, Helper helper)
     {...}

     static class UriHolder
     {
           @Inject(optional=true) @Assisted URI value;
     }
    }

    but UriHolder.uri is always null. Any ideas?

    Thanks,
    Gili

    --
    You received this message because you are subscribed to the Google
    Groups "google-guice" group.
    To post to this group, send email to [email protected]
    <mailto:[email protected]>.
    To unsubscribe from this group, send email to
    [email protected]
    <mailto:google-guice%[email protected]>.
    For more options, visit this group at
    http://groups.google.com/group/google-guice?hl=en.


--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.

--
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to