I am trying to bind instance provided by a ThrowingProvider into MapBinder. 
But I don't know how to do this.

I have a SslHandlerProvider provides a SSL channel handler.

public interface SslHandlerProvider extends CheckedProvider<ChannelHandler>{
    ChannelHandler get() throws SslException;
}

Here's the implementation :

public class SslHandlerProviderImpl implements SslHandlerProvider{

    @Inject SslContextProvider context;

    @Inject SslContextConfig config;

    @Override
    public ChannelHandler get() throws SslException {
        SSLEngine engine = context.get().createSSLEngine();
        engine.setUseClientMode(config.isClientMode());
        return new SslHandler(engine);
    }

}

In module config, I want to bind a SSLHandler into the MapBinder, but this 
cause a compile errorThe method toProvider(Provider<? extends 
ChannelHandler>) in the type LinkedBindingBuilder<ChannelHandler> is not 
applicable for the arguments (Class<SslHandlerProvider>) when I use 
.toProvider method.

MapBinder<String, ChannelHandler> handlerBinder = 
MapBinder.newMapBinder(binder(), String.class, ChannelHandler.class);
//This will cause compile error:
//handlerBinder.addHandler("ssl").toProvider(SslHandlerProvider.class).in(Scopes.NO_SCOPE);

handlerBinder.addHandler("encoder").to(JsonEncoder.class).in(Scopes.NO_SCOPE);
handlerBinder.addHandler("decoder").to(JsonDecoder.class).in(Scopes.NO_SCOPE);

So How could I do this ? Any answer or suggestion is appreciated. Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/c7f62ce8-89ca-453e-aa55-5bcdd877d705%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to