Package com.google.inject

Examples of com.google.inject.AbstractModule


    return context;
  }
 
  @Override
  public Module getModule() {
    return new AbstractModule() {
      @Override
      protected void configure() {
        bind(JpaContext.class).toProvider(JpaContextProvider.class);
      }
    };
View Full Code Here


        }
        moduleList.add(new AppCacheModule());
        boolean disableMysql = settings.getAsBoolean(ServiceFramwork.mode + ".datasources.mysql.disable", false);

        if (!disableMysql) {
            moduleList.add(new AbstractModule() {
                @Override
                protected void configure() {
                    bind(DBInfo.class).in(Singleton.class);
                }
            });
            moduleList.add(new AbstractModule() {
                @Override
                protected void configure() {
                    String clzzName = settings.get("type_mapping", "net.csdn.jpa.type.impl.MysqlType");
                    final Class czz;
                    try {
View Full Code Here

                        logger.info("util load :    "+ctClass.getName());
                        final Class clzz = ctClass.toClass();
                        final Util util = (Util) clzz.getAnnotation(Util.class);
                        if (clzz.isInterface())
                            throw new AnnotationException(format("{} util should not be interface", clzz.getName()));
                        moduleList.add(new AbstractModule() {
                            @Override
                            protected void configure() {
                                bind(clzz).in(util.value());
                            }
                        });
View Full Code Here

        ServiceFramwork.injector = ServiceFramwork.injector.createChildInjector(moduleList);
    }


    private static Module bindAction(final Class clzz) {
        return new AbstractModule() {
            @Override
            protected void configure() {
                if (clzz == null) return;
                try {
                    boolean isController = false;
View Full Code Here

        }
        for (final Class clzz : ctClasses) {

            if (clzz.getAnnotation(Singleton.class) != null) {
                logger.info("load  service with @Singleton  => " + clzz.getName());
                moduleList.add(new AbstractModule() {
                    @Override
                    protected void configure() {
                        bind(clzz).in(Scopes.SINGLETON);
                    }
                });
                continue;
            }
            final Service service = (Service) clzz.getAnnotation(Service.class);

            if (service == null) continue;
            if (clzz.isInterface() && service.implementedBy() == null)
                throw new AnnotationException(format("{} no implemented class configured", clzz.getName()));

            moduleList.add(new AbstractModule() {
                @Override
                protected void configure() {
                    if (clzz.isInterface()) {
                        logger.info("load  service with @Service => " + clzz.getName() + " to " + service.implementedBy().getName() + " in " + service.value().getName());
                        bind(clzz).to(service.implementedBy()).in(service.value());
                    } else {
                        logger.info("load  service with @Service => " + clzz.getName() + " in " + service.value().getName());
                        bind(clzz).in(service.value());
                    }

                }
            });
        }
        for (final Map.Entry<String, String> entry : settings.getByPrefix("application.dynamic.implemented.singleton").getAsMap().entrySet()) {
            moduleList.add(new AbstractModule() {
                @Override
                protected void configure() {
                    try {
                        Class clzz = Class.forName(entry.getValue());
                        bind(Class.forName(entry.getKey())).to(clzz).in(Scopes.SINGLETON);
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    }
                }
            });
        }

        for (final Map.Entry<String, String> entry : settings.getByPrefix("application.dynamic.implemented.prototype").getAsMap().entrySet()) {
            moduleList.add(new AbstractModule() {
                @Override
                protected void configure() {
                    try {
                        Class clzz = Class.forName(entry.getValue());
                        bind(Class.forName(entry.getKey())).to(clzz).in(Scopes.NO_SCOPE);
View Full Code Here

        final ObjectMapper objectMapper = buildObjectMapper();
        Json.setObjectMapper(objectMapper);

        final List<Module> modules = Lists.newArrayList();
        modules.add(new AbstractModule() {
            @Override
            protected void configure() {
                bind(URI[].class).annotatedWith(Names.named("Initial Nodes")).toInstance(initialNodes);
                bind(Long.class).annotatedWith(Names.named("Default Timeout"))
                        .toInstance(org.graylog2.restclient.lib.Configuration.apiTimeout("DEFAULT"));
View Full Code Here

    public Injector setupGuice(final Collection<URI> initialNodes) {
        List<Module> modules = Lists.newArrayList();
        modules.add(new ModelFactoryModule());

        modules.add(new AbstractModule() {
            @Override
            protected void configure() {
                bind(URI[].class).annotatedWith(Names.named("Initial Nodes")).toInstance(initialNodes.toArray(new URI[initialNodes.size()]));
                bind(Long.class).annotatedWith(Names.named("Default Timeout")).toInstance(TimeUnit.SECONDS.toMillis(5));
            }
View Full Code Here

    }
   
    @Test
    public void shouldNotCreateLazyTransitiveSingleton_Production_Child() {
        Injector injector = LifecycleInjector.builder()
                .withModules(new AbstractModule() {
                    @Override
                    protected void configure() {
                        bind(ThisShouldBeEager.class);
                    }
                })
View Full Code Here

   
    @Test
    public void shouldCreateAllSingletons_Production_NoChild() {
        Injector injector = LifecycleInjector.builder()
            .withMode(LifecycleInjectorMode.SIMULATED_CHILD_INJECTORS)
            .withModules(new AbstractModule() {
                @Override
                protected void configure() {
                    bind(ThisShouldBeEager.class);
                }
            })
View Full Code Here

    @Test
    public void shouldNotCreateLazyTransitiveSingleton_Development_NoChild() {
        Injector injector = LifecycleInjector.builder()
            .inStage(Stage.DEVELOPMENT)
            .withMode(LifecycleInjectorMode.SIMULATED_CHILD_INJECTORS)
            .withModules(new AbstractModule() {
                @Override
                protected void configure() {
                    bind(ThisShouldBeEager.class).asEagerSingleton();
                }
            })
View Full Code Here

TOP

Related Classes of com.google.inject.AbstractModule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.