-
Notifications
You must be signed in to change notification settings - Fork 56
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
feat(v2): Create Helper functions to retrieve client library instances through DIC #158
Conversation
…s through DIC For V2 APIs, each services will interact with other services through client libraries as defined in https://github.com/edgexfoundry/go-mod-core-contracts/tree/master/v2/clients, and each services will create their own helper functions to query DIC and get client instances. These helper functions could actually be shared among each services.Per suggestion from community, this commit creates these helper functions into go-mod-bootstrap. Signed-off-by: Jude Hung <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #158 +/- ##
=======================================
Coverage 54.41% 54.41%
=======================================
Files 14 14
Lines 612 612
=======================================
Hits 333 333
Misses 268 268
Partials 11 11 Continue to review full report at Codecov.
|
v2/bootstrap/container/common.go
Outdated
|
||
// CommonClientFrom helper function queries the DIC and returns the CommonClient instance. | ||
func CommonClientFrom(get di.Get) v2Clients.CommonClient { | ||
return get(CommonClientName).(v2Clients.CommonClient) |
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.
Please use the pattern here so nil
is properly retuned if DIC doesn't contain object.
https://github.com/edgexfoundry/go-mod-bootstrap/blob/master/bootstrap/container/configuration.go#L27
Same for all this implementations.
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.
Thanks! Modified through d642159
v2/bootstrap/container/common.go
Outdated
) | ||
|
||
// CommonClientName contains the name of the CommonClient instance in the DIC. | ||
var CommonClientName = "V2CommonClient" |
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.
Please use this form of creating the name for all these containers.
di.TypeInstanceToName((*interfaces.CommonClient)(nil))
This will create the name with the full path containing v2
and will not need to changed once we drop v2
when v1 code is removed.
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.
Thanks! Modified through d642159
v2/bootstrap/container/common.go
Outdated
|
||
import ( | ||
"github.com/edgexfoundry/go-mod-bootstrap/v2/di" | ||
v2Clients "github.com/edgexfoundry/go-mod-core-contracts/v2/v2/clients/interfaces" |
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.
Don't alias package unless it is needed to resolve name collision.
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 alias. d642159
1. use type assertion to handle nil case 2. use di.TypeInstanceToName to create the name of containers 3. drop unnecessary package alias Signed-off-by: Jude Hung <[email protected]>
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.
LGTM
PR Checklist
Please check if your PR fulfills the following requirements:
If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/go-mod-bootstrap/blob/master/.github/Contributing.md.
What is the current behavior?
Issue Number:
fix #157
What is the new behavior?
For V2 APIs, each services will interact with other services through client libraries as defined in https://github.com/edgexfoundry/go-mod-core-contracts/tree/master/v2/clients, and each services will create their own helper functions to query DIC and get client instances. These helper functions could actually be shared among each services. Per suggestion from community, this PR creates these helper functions into go-mod-bootstrap.
Does this PR introduce a breaking change?
New Imports