se.jbee.inject.service.ExtensionModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of silk-di Show documentation
Show all versions of silk-di Show documentation
Silk Java dependency injection framework
/*
* Copyright (c) 2012, Jan Bernitt
*
* Licensed under the Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0
*/
package se.jbee.inject.service;
import static se.jbee.inject.Name.named;
import static se.jbee.inject.Type.raw;
import se.jbee.inject.Dependency;
import se.jbee.inject.Name;
import se.jbee.inject.bind.Binder;
import se.jbee.inject.bind.BinderModule;
public abstract class ExtensionModule
extends BinderModule {
public static & Extension, T> void extend( Binder binder,
Class extension, Class extends T> type ) {
binder.multibind( extensionName( extension, type ), Class.class ).to( type );
binder.bind( type ).toConstructor(); //TODO implicit
}
public static & Extension, T> void extend( Binder binder,
E extension, Class extends T> type ) {
binder.multibind( extensionName( extension, type ), Class.class ).to( type );
binder.bind( type ).toConstructor(); //TODO implicit
}
public static & Extension, T> Name extensionName(
Class extension, Class extends T> type ) {
return named( extension.getCanonicalName() + ":" + type.getCanonicalName() );
}
public static & Extension, T> Name extensionName( E extension,
Class extends T> type ) {
return named( extension.getClass().getCanonicalName() + ":" + extension.name() + ":"
+ type.getCanonicalName() );
}
@SuppressWarnings ( { "rawtypes" } )
public static & Extension, T> Dependency extensionDependency(
Class extension ) {
return Dependency.dependency( raw( Class[].class ).parametizedAsLowerBounds() ).named(
Name.prefixed( extension.getCanonicalName() + ":" ) );
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy