From 50f7c08345a61863dd14d94d6ee52256d47cd9b5 Mon Sep 17 00:00:00 2001 From: Andrus Adamchik Date: Sat, 9 Dec 2023 17:25:29 -0500 Subject: [PATCH] Switching to injectable factories per bootique/bootique#345 --- .../bootique/linkmove/v3/LinkMoveFactory.java | 18 +++++++++++++++--- .../bootique/linkmove/v3/LinkMoveModule.java | 14 ++------------ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/bootique-linkmove3/src/main/java/io/bootique/linkmove/v3/LinkMoveFactory.java b/bootique-linkmove3/src/main/java/io/bootique/linkmove/v3/LinkMoveFactory.java index 3e97207..e0a5807 100644 --- a/bootique-linkmove3/src/main/java/io/bootique/linkmove/v3/LinkMoveFactory.java +++ b/bootique-linkmove3/src/main/java/io/bootique/linkmove/v3/LinkMoveFactory.java @@ -31,6 +31,7 @@ import io.bootique.resource.FolderResourceFactory; import org.apache.cayenne.configuration.server.ServerRuntime; +import javax.inject.Inject; import java.io.File; import java.net.URISyntaxException; import java.net.URL; @@ -45,12 +46,23 @@ @BQConfig public class LinkMoveFactory { + private final ServerRuntime targetRuntime; + private final Set> connectorFactories; + private final Set buildCallbacks; + private FolderResourceFactory extractorsDir; - public LmRuntime createLinkMove( + @Inject + public LinkMoveFactory( ServerRuntime targetRuntime, Set> connectorFactories, - Set builderCallbacks) { + Set buildCallbacks) { + this.targetRuntime = targetRuntime; + this.connectorFactories = connectorFactories; + this.buildCallbacks = buildCallbacks; + } + + public LmRuntime create() { ResourceResolver resolver = createResolver(); LmRuntimeBuilder builder = LmRuntime.builder() @@ -59,7 +71,7 @@ public LmRuntime createLinkMove( connectorFactories.forEach(builder::connectorFactory); - builderCallbacks.forEach(c -> c.build(builder)); + buildCallbacks.forEach(c -> c.build(builder)); return builder.build(); } diff --git a/bootique-linkmove3/src/main/java/io/bootique/linkmove/v3/LinkMoveModule.java b/bootique-linkmove3/src/main/java/io/bootique/linkmove/v3/LinkMoveModule.java index b9d36ca..3fe0d99 100644 --- a/bootique-linkmove3/src/main/java/io/bootique/linkmove/v3/LinkMoveModule.java +++ b/bootique-linkmove3/src/main/java/io/bootique/linkmove/v3/LinkMoveModule.java @@ -20,7 +20,6 @@ package io.bootique.linkmove.v3; import com.nhl.link.move.runtime.LmRuntime; -import com.nhl.link.move.runtime.connect.IConnectorFactory; import io.bootique.BQModule; import io.bootique.ModuleCrate; import io.bootique.config.ConfigurationFactory; @@ -28,10 +27,8 @@ import io.bootique.di.Provides; import io.bootique.jdbc.DataSourceFactory; import io.bootique.linkmove.v3.connector.JdbcConnectorFactory; -import org.apache.cayenne.configuration.server.ServerRuntime; import javax.inject.Singleton; -import java.util.Set; /** * @since 2.0 @@ -67,15 +64,8 @@ public void configure(Binder binder) { @Singleton @Provides - LmRuntime provideLinkMoveRuntime( - ConfigurationFactory configFactory, - ServerRuntime targetRuntime, - Set> connectorFactories, - Set buildCallbacks) { - - return configFactory - .config(LinkMoveFactory.class, CONFIG_PREFIX) - .createLinkMove(targetRuntime, connectorFactories, buildCallbacks); + LmRuntime provideLinkMoveRuntime(ConfigurationFactory configFactory) { + return configFactory.config(LinkMoveFactory.class, CONFIG_PREFIX).create(); } @Singleton