/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.facebook.presto; import com.google.inject.Binder; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Module; import com.google.inject.Scopes; import com.google.inject.multibindings.MapBinder; import org.weakref.jmx.guice.ExportBinder; import javax.inject.Inject; import java.util.Arrays; import java.util.Map; public class Main { public static void main(String[] args) { Injector injector = Guice.createInjector(new Module() { @Override public void configure(Binder binder) { ExportBinder exportBinder = ExportBinder.newExporter(binder); MapBinder mapBinder = MapBinder.newMapBinder(binder, String.class, Stats.class); int i = 0; for (Class clazz : Arrays.asList(Stats1.class, Stats2.class, Stats3.class)) { binder.bind(clazz).in(Scopes.SINGLETON); mapBinder.addBinding("stats" + i).to(Stats1.class); exportBinder.export(clazz).withGeneratedName(); i++; } binder.bind(Updater1.class).in(Scopes.SINGLETON); binder.bind(Updater2.class).in(Scopes.SINGLETON); binder.bind(Reporter.class).in(Scopes.SINGLETON); } }); Reporter reporter = injector.getInstance(Reporter.class); } public static interface Stats { } public static class Stats1 implements Stats {} public static class Stats2 implements Stats {} public static class Stats3 implements Stats {} public static class Updater1 { @Inject public Updater1(Stats1 stats) {} } public static class Updater2 { @Inject public Updater2(Stats2 stats2, Stats3 stats3) {} } public static class Reporter { @Inject public Reporter(Map stats) { System.out.println(stats); } } }