-
Notifications
You must be signed in to change notification settings - Fork 15
Refactor/make query a service #374
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
Conversation
| */ | ||
| private get blockExplorerTransport(): BlockExplorerTransportModule { | ||
| if (this.BlockExplorerTransport === undefined) { | ||
| if (!this.container.isRegistered("BlockExplorerTransportModule")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can save this line, tsyringe will throw a more descriptive error when it can't resolve a dependency anyways
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for all the others in this class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed since it is injected now: 3385f1d
| AppChainModules extends MinimalAppChainDefinition, | ||
| > extends AppChain<AppChainModules> { | ||
| // Optional for our lazy initialization purpose. | ||
| private QueryService?: QueryService< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lowercase
| MandatoryProtocolModulesRecord, | ||
| > { | ||
| // Here, fields are optional for lazy initialization. | ||
| private QueryTransport?: QueryTransportModule; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So - I had a bit of a different structure in mind here - and I think this would save a lot of LOCs:
We use all the features the tsyringe gives us.
First, we make the QueryService @injectable() and @scoped(Lifecycle.ContainerScoped)
Then, we inject al the transport module in the constructor using @inject("Token", { isOptional: true }) private readonly module: Module | undefined
And then, we can use this.module for all the actual queries that we have
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, in the ClientAppChain, we need to use this.parentContainer.resolve(QueryService)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
This PR refactors query logic in
ClientAppChainby extracting it into a dedicatedQueryServiceclass with lazy initialization patterns.Changes
QueryServiceclass with lazy-initialized getters for runtime, protocol, network, and explorer query modules f00c371QueryTransportModule,NetworkStateTransportModule,BlockExplorerTransportModulef00c371QueryServicefor query modules 23b6d4bClientAppChainto useQueryService880358fThis PR closes #349