Status: New
Owner: ----

New issue 798 by chatree.srich...@gmail.com: Let factory create an object depends on annotation defined at left hand side?
http://code.google.com/p/google-guice/issues/detail?id=798

Description of the issue:

Is it possible to let factory create an object depends on annotation defined at left hand side?

At the moment I have 2 annotation types, A and B.

@Retention(RetentionPolicy.RUNTIME)
@BindingAnnotation
public @interface A {}

@Retention(RetentionPolicy.RUNTIME)
@BindingAnnotation
public @interface B {}


And interface and its implementation:

public interface ResultSet {}
public class ResultSetA implements ResultSet {}
public class ResultSetA implements ResultSet {}


I have a factory.

public interface ResultSetFactory {

    @A
    public ResultSet createResultSetA(String sql);

    @B
    public ResultSet createResultSetB(String sql);
}

And I setup the factory like this:

install(new FactoryModuleBuilder()
                .implement(ResultSet.class, A.class, ResultSetA.class)
                .implement(ResultSet.class, B.class, ResultSetB.class)
                .build(ResultSetFactory.class));

However, I don't want to create methods everytime I have a new ResultSet(*).
So I want to change the factory to be:

public interface ResultSetFactory {

    public ResultSet create(String sql);
}

And use the new factory like this:

@A ResultSet resultSetA = factory.create(sql);
@B ResultSet resultSetB = factory.create(sql);
...
...

So, my question is, is there any way to do like this?

--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-guice-dev+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice-dev@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice-dev.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to