use of org.lanternpowered.server.inject.option.OptionModule in project LanternServer by LanternPowered.
the class LanternModule method configure.
@Override
protected void configure() {
// Inject into sponge
requestStaticInjection(Sponge.class);
// Injection Points
install(new InjectionPointProvider());
install(new InjectablePropertyProvider());
// The logger
bind(Logger.class).toInstance(this.logger);
// Options
install(new OptionModule() {
@Override
protected void configure0() {
// Bind the arguments
bindArguments().toInstance(arguments);
// Bind the parser
bindParser().toInstance(optionParser);
// Expose the Option annotation
exposeOptions();
}
});
// Directories: Plugins, Libraries, Configs, ...
bindAndExposePath(DirectoryKeys.ROOT, DirectoryKeys.DefaultValues.ROOT);
// See below for all the other ones
// Basic Configuration Annotations
bindAndExpose(Path.class, ConfigDirAnnotation.SHARED).toProvider(SharedConfigDirAsPath.class).in(Scopes.SINGLETON);
bindAndExpose(File.class, ConfigDirAnnotation.SHARED).toProvider(SharedConfigDirAsFile.class).in(Scopes.SINGLETON);
// The Game
bindAndExpose(Server.class).to(LanternServer.class);
bindAndExpose(LanternServer.class);
bindAndExpose(Game.class).to(LanternGame.class);
bindAndExpose(MinecraftVersion.class).toInstance(LanternMinecraftVersion.CURRENT);
bindAndExpose(ServiceManager.class).to(LanternServiceManager.class);
bindAndExpose(AssetManager.class).to(LanternAssetManager.class);
bindAndExpose(GameRegistry.class).to(LanternGameRegistry.class);
bindAndExpose(TeleportHelper.class).to(LanternTeleportHelper.class);
bindAndExpose(Scheduler.class).to(LanternScheduler.class);
bindAndExpose(CommandManager.class).to(LanternCommandManager.class);
bindAndExpose(Platform.class).to(LanternPlatform.class);
bindAndExpose(EventManager.class).to(LanternEventManager.class);
bindAndExpose(ChannelRegistrar.class).to(LanternChannelRegistrar.class);
bindAndExpose(GameProfileManager.class).to(LanternGameProfileManager.class);
bindAndExpose(PropertyRegistry.class).to(LanternPropertyRegistry.class);
bindAndExpose(ConfigManager.class).to(LanternConfigManager.class);
bindAndExpose(PluginManager.class).to(LanternPluginManager.class);
bindAndExpose(DataManager.class).to(LanternDataManager.class);
bindAndExpose(PropertyRegistry.class).to(LanternPropertyRegistry.class);
bindAndExpose(CauseStackManager.class).toInstance(LanternCauseStackManager.INSTANCE);
bindAndExpose(MetricsConfigManager.class).to(LanternMetricsConfigManager.class);
// The Indexed Channel Binding
bindAndExpose(ChannelBinding.IndexedMessageChannel.class).toProvider(ChannelBindingProvider.Indexed.class);
bindAndExpose(ChannelBinding.IndexedMessageChannel.class, Named.class).toProvider(ChannelBindingProvider.Indexed.class);
bindAndExpose(ChannelBinding.IndexedMessageChannel.class, ChannelId.class).toProvider(ChannelBindingProvider.Indexed.class);
// The Raw Channel Binding
bindAndExpose(ChannelBinding.RawDataChannel.class).toProvider(ChannelBindingProvider.Raw.class);
bindAndExpose(ChannelBinding.RawDataChannel.class, Named.class).toProvider(ChannelBindingProvider.Raw.class);
bindAndExpose(ChannelBinding.RawDataChannel.class, ChannelId.class).toProvider(ChannelBindingProvider.Raw.class);
// Assets
bindAndExpose(Asset.class, Named.class).toProvider(PluginAssetProvider.class);
bindAndExpose(Asset.class, AssetId.class).toProvider(PluginAssetProvider.class);
// Internal Plugin Containers
bindAndExpose(PluginContainer.class, Names.named(InternalPluginsInfo.Api.IDENTIFIER)).to(InternalPluginContainer.Api.class);
bindAndExpose(PluginContainer.class, Names.named(InternalPluginsInfo.SpongePlatform.IDENTIFIER)).to(InternalPluginContainer.SpongePlatform.class);
bindAndExpose(PluginContainer.class, Names.named(InternalPluginsInfo.Minecraft.IDENTIFIER)).to(InternalPluginContainer.Minecraft.class);
bindAndExpose(PluginContainer.class, Names.named(InternalPluginsInfo.Implementation.IDENTIFIER)).to(InternalPluginContainer.Implementation.class);
// Loggers
bindAndExpose(Logger.class, Named.class).toProvider(NamedSlf4jLoggerProvider.class);
expose(org.apache.logging.log4j.Logger.class);
bindAndExpose(org.apache.logging.log4j.Logger.class, Named.class).toProvider(NamedLog4jLoggerProvider.class);
// Other Plugin Containers
bindAndExpose(PluginContainer.class, Named.class).toProvider(PluginContainerProvider.class);
// Sponge Executor Services
bindAndExpose(SpongeExecutorService.class, SynchronousExecutor.class).toProvider(SpongeExecutorServiceProvider.Synchronous.class);
bindAndExpose(SpongeExecutorService.class, AsynchronousExecutor.class).toProvider(SpongeExecutorServiceProvider.Asynchronous.class);
}
use of org.lanternpowered.server.inject.option.OptionModule in project LanternServer by LanternPowered.
the class InjectionTest method test.
@Test
public void test() {
final double valueA = 10.684;
final int valueB = 500;
final AbstractModule module = new AbstractModule() {
@Override
protected void configure() {
install(new InjectionPointProvider());
final OptionParser optionParser = new OptionParser();
optionParser.allowsUnrecognizedOptions();
install(new OptionModule() {
@Override
protected void configure0() {
bindArguments().toInstance(new String[] { "--my-option=" + valueB, "--my-other-option=" + valueA });
bindParser().toInstance(optionParser);
}
});
}
};
final Injector injector = Guice.createInjector(module);
final TestObject testObject = injector.getInstance(TestObject.class);
assertEquals(testObject.myOtherOption, valueA, GenericMath.DBL_EPSILON);
assertEquals(testObject.myOption, valueB);
}
Aggregations