/**
 * Copyright 2015 Netflix, Inc.
 *
 * 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.netflix.spectator.nflx;

import com.google.inject.AbstractModule;
import com.netflix.spectator.api.ExtendedRegistry;
import com.netflix.spectator.api.Registry;
import com.netflix.spectator.api.Spectator;
import iep.com.netflix.iep.rxnetty.RxNettyModule;

/**
 * Guice module to configure the appropriate bindings for running an application. Note that this
 * will configure it to use the global registry bindings for reporting. This also means that test
 * cases will not be completely isolated. For unit tests see
 * {@link com.netflix.spectator.nflx.TestModule}. Typical usage:
 *
 * <p><b>User code</b></p>
 * <pre>
 * public class Foo {
 *   private final Counter counter;
 *
 *  {@literal @}Inject
 *   public Foo(ExtendedRegistry registry) {
 *     counter = registry.counter("foo.doSomething");
 *   }
 *
 *   public void doSomething() {
 *     counter.increment();
 *   }
 * }
 * </pre>
 *
 * <p><b>Governator</b></p>
 * <p>One of the classes requires an {@link javax.annotation.PostConstruct} block to initialize
 * so governator should be used to manage the lifecycle as guice doesn't support it directly.</p>
 * <pre>
 * Injector injector = LifecycleInjector.builder()
 *   .withModules(new SpectatorModule())
 *   .build()
 *   .createInjector();
 * injector.getInstance(LifecycleManager.class).start();
 * </pre>
 */
public final class SpectatorModule extends AbstractModule {
  @Override protected void configure() {
    install(new RxNettyModule());
    bind(Plugin.class).asEagerSingleton();
    bind(ExtendedRegistry.class).toInstance(Spectator.registry());
    bind(Registry.class).toInstance(Spectator.registry());
  }

  @Override public boolean equals(Object obj) {
    return obj != null && getClass().equals(obj.getClass());
  }

  @Override public int hashCode() {
    return getClass().hashCode();
  }
}

@@ -639,40 +639,158 @@
 ort 
-com.google.inject.AbstractModule
+iep.com.netflix.iep.rxnetty.RxNettyModule;%0A%0Aimport javax.inject.Singleton;%0A%0Aimport com.google.inject.AbstractModule;%0Aimport com.google.inject.Provides
 ;%0Aim
@@ -873,32 +873,32 @@
 r.api.Registry;%0A
+
 import com.netfl
@@ -928,58 +928,8 @@
 tor;
-%0Aimport iep.com.netflix.iep.rxnetty.RxNettyModule;
 %0A%0A/*
@@ -2185,50 +2185,92 @@
 ;%0A  
-  bind(ExtendedRegistry.class).toInstance(
+%7D%0A%0A  @Provides%0A  @Singleton%0A  ExtendedRegistry getExtendedRegistry() %7B%0A      return 
 Spec
@@ -2289,47 +2289,82 @@
 ry()
-)
 ;%0A  
-  bind(Registry.class).toInstance(
+%7D%0A  %0A  @Provides%0A  @Singleton%0A  Registry getRegistry() %7B%0A      return 
 Spec
@@ -2379,23 +2379,24 @@
 gistry()
-)
 ;%0A  %7D%0A
+  
 %0A  @Over

Move ExtendedRegistry and Registry bindings into @Provides to avoid triggering static initialization of these classes from within configure().