Skip to content

Commit

Permalink
Injecting BlockNodeContext using Dagger
Browse files Browse the repository at this point in the history
Signed-off-by: Alfredo Gutierrez <[email protected]>
  • Loading branch information
AlfredoG87 committed Aug 21, 2024
1 parent d1b5d62 commit 4d3dfea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.hedera.block.server;

import com.hedera.block.server.config.BlockNodeContext;
import com.hedera.block.server.config.BlockNodeContextFactory;
import com.hedera.block.server.data.ObjectEvent;
import com.hedera.block.server.health.HealthService;
import com.hedera.block.server.mediator.LiveStreamMediatorBuilder;
Expand Down Expand Up @@ -46,6 +45,7 @@ public class BlockNodeApp {
private static final System.Logger LOGGER = System.getLogger(Server.class.getName());
private final ServiceStatus serviceStatus;
private final HealthService healthService;
private final BlockNodeContext blockNodeContext;

/**
* Has all needed dependencies to start the server and initialize the context.
Expand All @@ -55,9 +55,12 @@ public class BlockNodeApp {
*/
@Inject
public BlockNodeApp(
@NonNull ServiceStatus serviceStatus, @NonNull HealthService healthService) {
@NonNull ServiceStatus serviceStatus,
@NonNull HealthService healthService,
@NonNull BlockNodeContext blockNodeContext) {
this.serviceStatus = serviceStatus;
this.healthService = healthService;
this.blockNodeContext = blockNodeContext;
}

/**
Expand All @@ -66,8 +69,6 @@ public BlockNodeApp(
* @throws IOException if the server cannot be started
*/
public void startServer() throws IOException {
// init context, metrics, and configuration.
@NonNull final BlockNodeContext blockNodeContext = BlockNodeContextFactory.create();

@NonNull
final BlockWriter<com.hedera.block.protos.BlockStreamService.BlockItem> blockWriter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@

package com.hedera.block.server;

import com.hedera.block.server.config.BlockNodeContext;
import com.hedera.block.server.config.BlockNodeContextFactory;
import dagger.Binds;
import dagger.Module;
import dagger.Provides;

import javax.inject.Singleton;
import java.io.IOException;

/**
* A Dagger Module for interfaces that are at the BlockNodeApp Level, should be temporary and
Expand All @@ -36,4 +41,18 @@ public interface BlockNodeAppInjectionModule {
@Singleton
@Binds
ServiceStatus bindServiceStatus(ServiceStatusImpl serviceStatus);

/**
* Provides a block node context singleton using the factory.
* @return a block node context singleton
*/
@Provides
@Singleton
static BlockNodeContext provideBlockNodeContext() {
try {
return BlockNodeContextFactory.create();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 4d3dfea

Please sign in to comment.