Skip to content

Commit

Permalink
Switching to injectable factories per bootique/bootique#345
Browse files Browse the repository at this point in the history
  • Loading branch information
andrus committed Dec 9, 2023
1 parent 5c43b3f commit 50f7c08
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,12 +46,23 @@
@BQConfig
public class LinkMoveFactory {

private final ServerRuntime targetRuntime;
private final Set<IConnectorFactory<?>> connectorFactories;
private final Set<LinkMoveBuilderCallback> buildCallbacks;

private FolderResourceFactory extractorsDir;

public LmRuntime createLinkMove(
@Inject
public LinkMoveFactory(
ServerRuntime targetRuntime,
Set<IConnectorFactory<?>> connectorFactories,
Set<LinkMoveBuilderCallback> builderCallbacks) {
Set<LinkMoveBuilderCallback> buildCallbacks) {
this.targetRuntime = targetRuntime;
this.connectorFactories = connectorFactories;
this.buildCallbacks = buildCallbacks;
}

public LmRuntime create() {

ResourceResolver resolver = createResolver();
LmRuntimeBuilder builder = LmRuntime.builder()
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@
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;
import io.bootique.di.Binder;
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
Expand Down Expand Up @@ -67,15 +64,8 @@ public void configure(Binder binder) {

@Singleton
@Provides
LmRuntime provideLinkMoveRuntime(
ConfigurationFactory configFactory,
ServerRuntime targetRuntime,
Set<IConnectorFactory<?>> connectorFactories,
Set<LinkMoveBuilderCallback> 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
Expand Down

0 comments on commit 50f7c08

Please sign in to comment.