All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sitebricks.client.easy.internal.RestClientFactoryProvider Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright (c) 2011 Sonatype, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Apache License v2.0 which accompanies this distribution.
 * The Eclipse Public License is available at
 *   http://www.eclipse.org/legal/epl-v10.html
 * The Apache License v2.0 is available at
 *   http://www.apache.org/licenses/LICENSE-2.0.html
 * You may elect to redistribute this code under either of these licenses.
 *******************************************************************************/
package org.sitebricks.client.easy.internal;

import com.google.inject.Injector;
import com.google.inject.Provider;
import com.google.inject.spi.Toolable;

import org.sitebricks.client.easy.RestClientFactory;

import javax.inject.Inject;
import java.util.Map;

public class RestClientFactoryProvider implements Provider> {

  private final Class serviceInterface;

  private Injector injector;

  private final Map bindings;

  public RestClientFactoryProvider(final Class serviceInterface, final Map bindings) {
    this.serviceInterface = serviceInterface;
    this.bindings = bindings;
  }

  @Override
  public RestClientFactory get() {
    final DefaultRestClientFactory restClientFactory = new DefaultRestClientFactory(serviceInterface, bindings);
    injector.injectMembers(restClientFactory);
    return restClientFactory;
  }

  @Inject
  @Toolable
  void initialize(final Injector injector) {
    this.injector = injector;
  }

}