public interface Provider<T> {
T get();
}
public class DatabaseTransactionLogProvider implements Provider<TransactionLog> {
private final Connection connection;
@Inject
public DatabaseTransactionLogProvider(Connection connection) {
this.connection = connection;
}
public TransactionLog get() {
DatabaseTransactionLog transactionLog = new DatabaseTransactionLog();
transactionLog.setConnection(connection);
return transactionLog;
}
}
@ELDPlugin(
registry = TesterRegistry.class,
lifeCycle = TesterLifeCycle.class
)
public class ELDTester extends ELDBukkitPlugin {
@Override
protected void bindServices(ServiceCollection serviceCollection) {
serviceCollection.bindServiceProvider(TransactionLog.class, DatabaseTransactionLogProvider.class);
}
@Override
protected void manageProvider(ManagerProvider provider) {
}
}
public class LogService {
@Inject
private Provider<TransactionLog> logProvider;
public void log(String message){
TransactionLog logger = logProvider.get();
// do something ....
}
}