Skip to content
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

Merged
merged 2 commits into from
Jan 26, 2021

Conversation

judehung
Copy link
Member

@judehung judehung commented Jan 25, 2021

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

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?

  • Yes
  • No

New Imports

  • Yes
  • No

…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-io
Copy link

Codecov Report

Merging #158 (182e899) into master (ec2d1cf) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ec2d1cf...182e899. Read the comment docs.


// CommonClientFrom helper function queries the DIC and returns the CommonClient instance.
func CommonClientFrom(get di.Get) v2Clients.CommonClient {
return get(CommonClientName).(v2Clients.CommonClient)
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Modified through d642159

)

// CommonClientName contains the name of the CommonClient instance in the DIC.
var CommonClientName = "V2CommonClient"
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Modified through d642159


import (
"github.com/edgexfoundry/go-mod-bootstrap/v2/di"
v2Clients "github.com/edgexfoundry/go-mod-core-contracts/v2/v2/clients/interfaces"
Copy link
Member

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.

Copy link
Member Author

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]>
Copy link
Member

@lenny-goodell lenny-goodell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lenny-goodell lenny-goodell merged commit 3d89601 into edgexfoundry:master Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[V2] Create Helper functions to retrieve client library instances through DIC
3 participants