Search in sources :

Example 6 with AbstractModule

use of com.google.inject.AbstractModule in project eureka by Netflix.

the class EurekaModuleTest method setUp.

@Before
public void setUp() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("eureka.region", "default");
    ConfigurationManager.getConfigInstance().setProperty("eureka.shouldFetchRegistry", "false");
    ConfigurationManager.getConfigInstance().setProperty("eureka.registration.enabled", "false");
    ConfigurationManager.getConfigInstance().setProperty("eureka.serviceUrl.default", "http://localhost:8080/eureka/v2");
    injector = InjectorBuilder.fromModule(new EurekaModule()).overrideWith(new AbstractModule() {

        @Override
        protected void configure() {
            // the default impl of EurekaInstanceConfig is CloudInstanceConfig, which we only want in an AWS
            // environment. Here we override that by binding MyDataCenterInstanceConfig to EurekaInstanceConfig.
            bind(EurekaInstanceConfig.class).toProvider(MyDataCenterInstanceConfigProvider.class).in(Scopes.SINGLETON);
        }
    }).createInjector();
}
Also used : EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Example 7 with AbstractModule

use of com.google.inject.AbstractModule in project ribbon by Netflix.

the class RxMovieProxyExampleTest method shouldBindCustomClientConfigFactory.

@Test
public void shouldBindCustomClientConfigFactory() {
    ConfigurationManager.getConfigInstance().setProperty(MovieService.class.getSimpleName() + ".MyConfig.listOfServers", "localhost:" + port);
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(RibbonResourceFactory.class).to(DefaultResourceFactory.class).in(Scopes.SINGLETON);
            bind(RibbonTransportFactory.class).to(DefaultRibbonTransportFactory.class).in(Scopes.SINGLETON);
            bind(AnnotationProcessorsProvider.class).to(DefaultAnnotationProcessorsProvider.class).in(Scopes.SINGLETON);
            bind(ClientConfigFactory.class).to(MyClientConfigFactory.class).in(Scopes.SINGLETON);
        }
    }, new AbstractModule() {

        @Override
        protected void configure() {
            bind(MovieService.class).toProvider(new RibbonResourceProvider<MovieService>(MovieService.class)).asEagerSingleton();
        }
    });
    RxMovieProxyExample example = injector.getInstance(RxMovieProxyExample.class);
    assertTrue(example.runExample());
}
Also used : MovieService(com.netflix.ribbon.examples.rx.proxy.MovieService) Injector(com.google.inject.Injector) DefaultClientConfigFactory(com.netflix.client.config.ClientConfigFactory.DefaultClientConfigFactory) ClientConfigFactory(com.netflix.client.config.ClientConfigFactory) RibbonTransportFactory(com.netflix.ribbon.RibbonTransportFactory) DefaultRibbonTransportFactory(com.netflix.ribbon.RibbonTransportFactory.DefaultRibbonTransportFactory) RibbonResourceFactory(com.netflix.ribbon.RibbonResourceFactory) DefaultAnnotationProcessorsProvider(com.netflix.ribbon.proxy.processor.AnnotationProcessorsProvider.DefaultAnnotationProcessorsProvider) AnnotationProcessorsProvider(com.netflix.ribbon.proxy.processor.AnnotationProcessorsProvider) RxMovieProxyExample(com.netflix.ribbon.examples.rx.proxy.RxMovieProxyExample) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 8 with AbstractModule

use of com.google.inject.AbstractModule in project ninja by ninjaframework.

the class FileItemProviderImpl2 method init.

public void init(final Class<? extends FileItemProvider> fileItemProviderClass) throws IOException, ServletException {
    //default setup for httpServlet request.
    //According to servlet spec the following will be returned:
    when(httpServletRequest.getContextPath()).thenReturn("");
    when(httpServletRequest.getRequestURI()).thenReturn("/");
    when(httpServletRequest.getContentType()).thenReturn("multipart/form-data");
    when(httpServletRequest.getMethod()).thenReturn("POST");
    NinjaPropertiesImpl properties = new NinjaPropertiesImpl(NinjaMode.test);
    this.ninjaProperties = properties;
    final FileItemIterator fileItemIterator = makeFileItemsIterator();
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(NinjaProperties.class).toInstance(ninjaProperties);
            bind(FileItemProvider.class).to(fileItemProviderClass);
        }
    });
    context = new NinjaServletContext(bodyParserEngineManager, flashCookie, ninjaProperties, resultHandler, sessionCookie, validation, injector, new ParamParsers(new HashSet<ParamParser>())) {

        public FileItemIterator getFileItemIterator() {
            return fileItemIterator;
        }

        ;
    };
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) ParamParser(ninja.params.ParamParser) ParamParsers(ninja.params.ParamParsers) Injector(com.google.inject.Injector) FileItemIterator(org.apache.commons.fileupload.FileItemIterator) AbstractModule(com.google.inject.AbstractModule)

Example 9 with AbstractModule

use of com.google.inject.AbstractModule in project ninja by ninjaframework.

the class LifecycleSupportTest method serviceShouldBeStartedIfExplicitlyBoundAndSingleton.

@Test
public void serviceShouldBeStartedIfExplicitlyBoundAndSingleton() {
    Injector injector = createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(MockSingletonService.class);
        }
    });
    start(injector);
    assertThat(MockSingletonService.started, equalTo(1));
}
Also used : Injector(com.google.inject.Injector) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 10 with AbstractModule

use of com.google.inject.AbstractModule in project ninja by ninjaframework.

the class LifecycleSupportTest method providedSingletonDisposableShouldBeDisposed.

@Test
public void providedSingletonDisposableShouldBeDisposed() {
    Injector injector = createInjector(new AbstractModule() {

        @Override
        protected void configure() {
        }

        @Provides
        @Singleton
        public MockSingletonService provide() {
            return new MockSingletonService();
        }
    });
    start(injector);
    stop(injector);
    assertThat(MockSingletonService.disposed, equalTo(1));
}
Also used : Injector(com.google.inject.Injector) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Aggregations

AbstractModule (com.google.inject.AbstractModule)840 Injector (com.google.inject.Injector)522 Module (com.google.inject.Module)232 CreationException (com.google.inject.CreationException)162 Provider (com.google.inject.Provider)64 Key (com.google.inject.Key)55 ConfigModule (co.cask.cdap.common.guice.ConfigModule)54 AuthorizationEnforcementModule (co.cask.cdap.security.authorization.AuthorizationEnforcementModule)49 DataSetsModules (co.cask.cdap.data.runtime.DataSetsModules)46 PrivateModule (com.google.inject.PrivateModule)46 AuthenticationContextModules (co.cask.cdap.security.auth.context.AuthenticationContextModules)45 AuthorizationTestModule (co.cask.cdap.security.authorization.AuthorizationTestModule)43 DiscoveryRuntimeModule (co.cask.cdap.common.guice.DiscoveryRuntimeModule)42 TypeLiteral (com.google.inject.TypeLiteral)42 BeforeClass (org.junit.BeforeClass)38 Map (java.util.Map)37 CConfiguration (co.cask.cdap.common.conf.CConfiguration)36 UnsupportedUGIProvider (co.cask.cdap.security.impersonation.UnsupportedUGIProvider)36 NonCustomLocationUnitTestModule (co.cask.cdap.common.guice.NonCustomLocationUnitTestModule)35 DefaultOwnerAdmin (co.cask.cdap.security.impersonation.DefaultOwnerAdmin)35