2 * Copyright (c) 2018 Red Hat, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.odlguice.inject.guice;
10 import com.google.inject.Binder;
11 import javax.inject.Singleton;
12 import org.opendaylight.odlguice.inject.ClassPathScanner;
15 * Binds interfaces to implementations in Guice by scanning the classpath.
17 public class GuiceClassPathBinder {
18 private final ClassPathScanner scanner;
20 public GuiceClassPathBinder(String prefix) {
21 this.scanner = new ClassPathScanner(prefix);
25 * Binds all {@link Singleton} annotated classes discovered by scanning the class path to all their interfaces.
27 * @param prefix the package prefix of Singleton implementations to consider
28 * @param binder The binder to set up.
30 @SuppressWarnings("unchecked")
31 public void bindAllSingletons(String prefix, Binder binder) {
32 scanner.bindAllSingletons(prefix,
33 (contract, implementation) -> binder.bind(contract).to(implementation),
34 singleton -> binder.bind(singleton));