info.magnolia.objectfactory.Components.named()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中info.magnolia.objectfactory.Components.named()方法的一些代码示例,展示了Components.named()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Components.named()方法的具体详情如下:
包路径:info.magnolia.objectfactory.Components
类名称:Components
方法名:named

Components.named介绍

暂无

代码示例

代码示例来源:origin: info.magnolia.cache/magnolia-cache-core

/**
 * @deprecated since 5.4.5 - use {@link CacheModule#CacheModule(CacheMonitor, EventBus)} instead.
 */
@Deprecated
public CacheModule(CacheMonitor cacheMonitor) {
  this(cacheMonitor, Components.getComponentWithAnnotation(EventBus.class, Components.named(SystemEventBus.NAME)));
}

代码示例来源:origin: info.magnolia/magnolia-core

/**
 * @deprecated since 5.4.5 use {@link #CommandsManager(ModuleRegistry, Node2BeanProcessor, EventBus)}
 */
@Deprecated
public CommandsManager(Node2BeanProcessor nodeToBean) {
  this(Components.getComponent(ModuleRegistry.class), nodeToBean, Components.getComponentWithAnnotation(EventBus.class, Components.named(SystemEventBus.NAME)));
}

代码示例来源:origin: info.magnolia/magnolia-core

private void installProperties(MagnoliaConfigurationProperties configurationProperties) {

    for (final String key : configurationProperties.getKeys()) {

      /*
        Unfortunately there's a trade off here. We CAN register these as providers, then properties can change
        and we can get the changed values using a provider. But then we dont get conversion to primitives such as
        boolean and int.
      */

/*
      binder().bind(Key.get(String.class, new NamedImpl(propertyName))).toProvider(new Provider<String>() {
        @Override
        public String get() {
          return SystemProperty.getProperty(configurationProperties.getProperty(key));
        }
      });
*/
      binder().bind(Key.get(String.class, Components.named(key))).toInstance(configurationProperties.getProperty(key));
    }
  }

代码示例来源:origin: info.magnolia/magnolia-core

@Override
  protected void configure() {
    bind(String.class).annotatedWith(Components.named("first")).toInstance("first");
    bind(String.class).annotatedWith(Components.named("second")).toInstance("second");
  }
});

代码示例来源:origin: info.magnolia/magnolia-core

@Override
  protected void configure() {
    bind(String.class).annotatedWith(Components.named("first")).toInstance("first");
    bind(String.class).annotatedWith(Components.named("second")).toInstance("second");
  }
});

代码示例来源:origin: info.magnolia/magnolia-core

@Test(expected = NoSuchComponentException.class)
  public void getComponentWithAnnotationThrowsExceptionIfComponentProviderIsNotAGuiceComponentProvider() {

    // WHEN
    Components.getComponentWithAnnotation(String.class, Components.named("third"));
  }
}

代码示例来源:origin: info.magnolia/magnolia-core

EventBus systemEventBus = Components.getComponentWithAnnotation(EventBus.class, Components.named(SystemEventBus.NAME));
systemEventBus.fireEvent(new ModulesStartedEvent());

代码示例来源:origin: info.magnolia/magnolia-core

@Test
public void getComponentWithAnnotationReturnsCorrectInstance() {
  // GIVEN
  GuiceComponentProviderBuilder builder = new GuiceComponentProviderBuilder();
  builder.addModule(new AbstractModule() {
    @Override
    protected void configure() {
      bind(String.class).annotatedWith(Components.named("first")).toInstance("first");
      bind(String.class).annotatedWith(Components.named("second")).toInstance("second");
    }
  });
  builder.exposeGlobally();
  builder.build();
  // THEN
  assertEquals("first", Components.getComponentWithAnnotation(String.class, Components.named("first")));
  assertEquals("second", Components.getComponentWithAnnotation(String.class, Components.named("second")));
}

代码示例来源:origin: info.magnolia/magnolia-core

@Test(expected = NoSuchComponentException.class)
public void getComponentWithAnnotationThrowsExceptionIfComponentNotConfigured() {
  // GIVEN
  GuiceComponentProviderBuilder builder = new GuiceComponentProviderBuilder();
  builder.addModule(new AbstractModule() {
    @Override
    protected void configure() {
      bind(String.class).annotatedWith(Components.named("first")).toInstance("first");
      bind(String.class).annotatedWith(Components.named("second")).toInstance("second");
    }
  });
  builder.exposeGlobally();
  builder.build();
  // WHEN
  Components.getComponentWithAnnotation(String.class, Components.named("third"));
}

相关文章