A have a builder that uses UriInfo, i would like to inject uri info into 
the builder and potentially a lot of other things.

@Path("test")
public class MyTest {

    @Context
    private ServiceLocator serviceLocator;

    @Inject
    private EntityBuilder entityBuilder;

    @GET
    public Response getEntity(@Context UriInfo uriInfo) {
        OldEntity test = OldEntity.builder()
                .setUriInfo(uriInfo)
                .template("test")
                .build();

        NewEntity test2 = new EntityBuilder()
                .template("test2")
                .build();

        EntityBuilder localBuilder = new EntityBuilder();

        serviceLocator.inject(localBuilder);

        NewEntity test3 = localBuilder
                .template("test3")
                .build();

        NewEntity test4 = entityBuilder
                .template("test4")
                .build();

        return Response.ok().build();
    }
}



   - *test *is the old builder which works without injection
   - *test2 *is the new builder which does not work
   - *test3 *works but i have to inject manually which i would like to avoid
   - *test4 *work but a have only one builder, which means if a build more 
   than one it overwrites the old.

The new builder is:

public class EntityBuilder {
    @Context
    private UriInfo uriInfo;

    private NewEntity newEntity;

    public EntityBuilder() {
        this.newEntity = new NewEntity();
    }

    public EntityBuilder template(String template) {
        this.newEntity.setTemplate(uriInfo.getAbsolutePath() + template);
        return this;
    }

    public NewEntity build() {
        return this.newEntity;
    }
}


The code has been simplified for clarity.

Is there a way i can inject every new instance of EntityBuilder? how do i 
get test2 to work?


-- 
You received this message because you are subscribed to the Google Groups 
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to