Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use singleton annotation instead of binding as singleton #3058

Merged
merged 4 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ configure(project(':common')) {
compile "ch.qos.logback:logback-classic:$logbackVersion"
compile 'com.google.code.findbugs:jsr305:3.0.2'
compile 'com.google.guava:guava:20.0'
compile('com.google.inject:guice:4.1.0') {
compile('com.google.inject:guice:4.2.2') {
exclude(module: 'guava')
}
compile("com.github.bisq-network.bitcoinj:bitcoinj-core:$bitcoinjVersion") {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/bisq/core/util/BSFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.bitcoinj.utils.MonetaryFormat;

import javax.inject.Inject;
import javax.inject.Singleton;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
Expand All @@ -59,6 +60,7 @@
import org.jetbrains.annotations.NotNull;

@Slf4j
@Singleton
public class BSFormatter {
public final static String RANGE_SEPARATOR = " - ";

Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/bisq/core/util/BsqFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.bitcoinj.utils.MonetaryFormat;

import javax.inject.Inject;
import javax.inject.Singleton;

import java.text.DecimalFormat;
import java.text.NumberFormat;
Expand All @@ -44,6 +45,7 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Singleton
public class BsqFormatter extends BSFormatter {
@SuppressWarnings("PointlessBooleanExpression")
private static final boolean useBsqAddressFormat = true || !DevEnv.isDevMode();
Expand Down
36 changes: 0 additions & 36 deletions desktop/src/main/java/bisq/desktop/DesktopModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,12 @@
package bisq.desktop;

import bisq.desktop.common.fxml.FxmlViewLoader;
import bisq.desktop.common.view.CachingViewLoader;
import bisq.desktop.common.view.ViewFactory;
import bisq.desktop.common.view.ViewLoader;
import bisq.desktop.common.view.guice.InjectorViewFactory;
import bisq.desktop.main.dao.bonding.BondingViewUtils;
import bisq.desktop.main.funds.transactions.DisplayedTransactionsFactory;
import bisq.desktop.main.funds.transactions.TradableRepository;
import bisq.desktop.main.funds.transactions.TransactionAwareTradableFactory;
import bisq.desktop.main.funds.transactions.TransactionListItemFactory;
import bisq.desktop.main.offer.offerbook.OfferBook;
import bisq.desktop.main.overlays.notifications.NotificationCenter;
import bisq.desktop.main.overlays.windows.TorNetworkSettingsWindow;
import bisq.desktop.main.presentation.DaoPresentation;
import bisq.desktop.main.presentation.MarketPricePresentation;
import bisq.desktop.util.Transitions;

import bisq.core.app.AppOptionKeys;
import bisq.core.locale.Res;
import bisq.core.util.BSFormatter;
import bisq.core.util.BsqFormatter;

import bisq.common.app.AppModule;

Expand All @@ -57,32 +43,10 @@ public DesktopModule(Environment environment) {

@Override
protected void configure() {
bind(InjectorViewFactory.class).in(Singleton.class);
bind(ViewFactory.class).to(InjectorViewFactory.class);
bind(CachingViewLoader.class).in(Singleton.class);

bind(ResourceBundle.class).toInstance(Res.getResourceBundle());
bind(ViewLoader.class).to(FxmlViewLoader.class).in(Singleton.class);
bind(CachingViewLoader.class).in(Singleton.class);

bind(Navigation.class).in(Singleton.class);
bind(NotificationCenter.class).in(Singleton.class);

bind(OfferBook.class).in(Singleton.class);
bind(BSFormatter.class).in(Singleton.class);
bind(BsqFormatter.class).in(Singleton.class);
bind(TorNetworkSettingsWindow.class).in(Singleton.class);
bind(MarketPricePresentation.class).in(Singleton.class);
bind(DaoPresentation.class).in(Singleton.class);

bind(Transitions.class).in(Singleton.class);

bind(TradableRepository.class).in(Singleton.class);
bind(TransactionListItemFactory.class).in(Singleton.class);
bind(TransactionAwareTradableFactory.class).in(Singleton.class);
bind(DisplayedTransactionsFactory.class).in(Singleton.class);

bind(BondingViewUtils.class).in(Singleton.class);

bindConstant().annotatedWith(Names.named(AppOptionKeys.APP_NAME_KEY)).to(environment.getRequiredProperty(AppOptionKeys.APP_NAME_KEY));
}
Expand Down
3 changes: 3 additions & 0 deletions desktop/src/main/java/bisq/desktop/Navigation.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import com.google.inject.Inject;

import javax.inject.Singleton;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand All @@ -41,6 +43,7 @@
import javax.annotation.Nullable;

@Slf4j
@Singleton
public final class Navigation implements PersistedDataHost {
private static final ViewPath DEFAULT_VIEW_PATH = ViewPath.to(MainView.class, MarketView.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.core.annotation.AnnotationUtils;

import javax.inject.Inject;
import javax.inject.Singleton;

import javafx.fxml.FXMLLoader;

Expand All @@ -38,6 +39,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static org.springframework.core.annotation.AnnotationUtils.getDefaultValue;

@Singleton
public class FxmlViewLoader implements ViewLoader {

private final ViewFactory viewFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
package bisq.desktop.common.view;

import javax.inject.Inject;
import javax.inject.Singleton;

import java.util.HashMap;

@Singleton
public class CachingViewLoader implements ViewLoader {

private final HashMap<Object, View> cache = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@

import com.google.inject.Injector;

import javax.inject.Singleton;

import com.google.common.base.Preconditions;

@Singleton
public class InjectorViewFactory implements ViewFactory {

private Injector injector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.bitcoinj.core.InsufficientMoneyException;

import javax.inject.Inject;
import javax.inject.Singleton;

import java.util.Optional;
import java.util.function.Consumer;
Expand All @@ -56,6 +57,7 @@
import static com.google.common.base.Preconditions.checkArgument;

@Slf4j
@Singleton
public class BondingViewUtils {
private final P2PService p2PService;
private final MyReputationListService myReputationListService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import bisq.core.btc.wallet.BtcWalletService;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class DisplayedTransactionsFactory {
private final BtcWalletService btcWalletService;
private final TradableRepository tradableRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import bisq.core.trade.failed.FailedTradesManager;

import javax.inject.Inject;
import javax.inject.Singleton;

import com.google.common.collect.ImmutableSet;

import java.util.Set;

@Singleton
public class TradableRepository {
private final OpenOfferManager openOfferManager;
private final TradeManager tradeManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import bisq.core.trade.Trade;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class TransactionAwareTradableFactory {
private final DisputeManager disputeManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
import org.bitcoinj.core.Transaction;

import javax.inject.Inject;
import javax.inject.Singleton;

import java.util.Optional;

import javax.annotation.Nullable;

@Singleton
public class TransactionListItemFactory {
private final BtcWalletService btcWalletService;
private final BsqWalletService bsqWalletService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import bisq.core.trade.TradeManager;

import javax.inject.Inject;
import javax.inject.Singleton;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
Expand All @@ -42,6 +43,7 @@
* It also use OfferRepository.Listener as the lists items class and we don't want to get any dependency out of the
* package for that.
*/
@Singleton
@Slf4j
public class OfferBook {
private final OfferBookService offerBookService;
Expand Down
4 changes: 2 additions & 2 deletions desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ protected enum Type {
private HPos buttonAlignment = HPos.RIGHT;

protected Optional<Runnable> closeHandlerOptional = Optional.<Runnable>empty();
protected Optional<Runnable> actionHandlerOptional = Optional.<Runnable>empty();
protected Optional<Runnable> actionHandlerOptional = Optional.empty();
protected Optional<Runnable> secondaryActionHandlerOptional = Optional.<Runnable>empty();
protected ChangeListener<Number> positionListener;

Expand Down Expand Up @@ -438,7 +438,7 @@ public T secondaryActionButtonText(String secondaryActionButtonText) {

public T useShutDownButton() {
this.actionButtonText = Res.get("shared.shutDown");
this.actionHandlerOptional = Optional.of(BisqApp.getShutDownHandler());
this.actionHandlerOptional = Optional.ofNullable(BisqApp.getShutDownHandler());
//noinspection unchecked
return (T) this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

import com.google.inject.Inject;

import javax.inject.Singleton;

import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.Subscription;

Expand All @@ -54,6 +56,7 @@
import javax.annotation.Nullable;

@Slf4j
@Singleton
public class NotificationCenter {

///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import bisq.common.util.Utilities;

import javax.inject.Inject;
import javax.inject.Singleton;

import javafx.scene.Scene;
import javafx.scene.control.Button;
Expand Down Expand Up @@ -72,6 +73,7 @@
import static bisq.desktop.util.FormBuilder.*;

@Slf4j
@Singleton
public class TorNetworkSettingsWindow extends Overlay<TorNetworkSettingsWindow> {

public enum BridgeOption {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import bisq.common.app.DevEnv;

import javax.inject.Inject;
import javax.inject.Singleton;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
Expand All @@ -25,6 +26,7 @@

import lombok.Getter;

@Singleton
public class DaoPresentation implements DaoStateListener {

public static final String DAO_NEWS = "daoNewsVersion1.0.0";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import bisq.common.UserThread;

import javax.inject.Inject;
import javax.inject.Singleton;

import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.Subscription;
Expand All @@ -60,6 +61,7 @@

import lombok.Getter;

@Singleton
public class MarketPricePresentation {
private final Preferences preferences;
private final BSFormatter formatter;
Expand Down
2 changes: 2 additions & 0 deletions desktop/src/main/java/bisq/desktop/util/Transitions.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import bisq.common.UserThread;

import javax.inject.Inject;
import javax.inject.Singleton;

import javafx.animation.FadeTransition;
import javafx.animation.Interpolator;
Expand All @@ -39,6 +40,7 @@

import javafx.util.Duration;

@Singleton
public class Transitions {

public final static int DEFAULT_DURATION = 600;
Expand Down
Loading