fix(client): to Guice DI pattern
This commit is contained in:
parent
7320dd1e46
commit
96b7241056
4 changed files with 9 additions and 5 deletions
|
|
@ -35,6 +35,7 @@ import com.google.inject.TypeLiteral;
|
|||
import commons.Ingredient;
|
||||
import commons.Recipe;
|
||||
|
||||
import java.net.http.HttpClient;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class MyModule implements Module {
|
||||
|
|
@ -51,6 +52,7 @@ public class MyModule implements Module {
|
|||
binder.bind(WebSocketUtils.class).in(Scopes.SINGLETON);
|
||||
binder.bind(NutritionDetailsCtrl.class).in(Scopes.SINGLETON);
|
||||
binder.bind(NutritionViewCtrl.class).in(Scopes.SINGLETON);
|
||||
binder.bind(HttpClient.class).in(Scopes.SINGLETON);
|
||||
binder.bind(ConfigService.class).toInstance(new ConfigService(Path.of("config.json")));
|
||||
binder.bind(new TypeLiteral<WebSocketDataService<Long, Recipe>>() {}).toInstance(
|
||||
new WebSocketDataService<>()
|
||||
|
|
@ -59,4 +61,4 @@ public class MyModule implements Module {
|
|||
new WebSocketDataService<>()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ public class ServerUtils {
|
|||
private final int statusOK = 200;
|
||||
|
||||
@Inject
|
||||
public ServerUtils() {
|
||||
client = HttpClient.newHttpClient();
|
||||
public ServerUtils(HttpClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue