From c087e444e0991f951877657a44d9c4abbb1fddb7 Mon Sep 17 00:00:00 2001 From: Jude Hung Date: Thu, 4 Feb 2021 02:18:11 +0800 Subject: [PATCH] feat(v2): Add helper to query DIC and returns the DeviceServiceCommandClient instance (#162) DeviceServiceCommandClient was added into go-mod-core-contracts, and we shall have corresponding helper function in go-mod-bootstrap to query DIC and then return the DeviceServiceCommandClient instance Signed-off-by: Jude Hung --- go.mod | 2 +- v2/bootstrap/container/deviceservice.go | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 631bfe47..14dffe54 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/edgexfoundry/go-mod-bootstrap/v2 require ( github.com/BurntSushi/toml v0.3.1 github.com/edgexfoundry/go-mod-configuration/v2 v2.0.0-dev.1 - github.com/edgexfoundry/go-mod-core-contracts/v2 v2.0.0-dev.13 + github.com/edgexfoundry/go-mod-core-contracts/v2 v2.0.0-dev.18 github.com/edgexfoundry/go-mod-registry/v2 v2.0.0-dev.1 github.com/edgexfoundry/go-mod-secrets/v2 v2.0.0-dev.3 github.com/gorilla/mux v1.7.1 diff --git a/v2/bootstrap/container/deviceservice.go b/v2/bootstrap/container/deviceservice.go index eb734072..346f98da 100644 --- a/v2/bootstrap/container/deviceservice.go +++ b/v2/bootstrap/container/deviceservice.go @@ -13,7 +13,10 @@ import ( // DeviceServiceCallbackClientName contains the name of the DeviceServiceCallbackClient instance in the DIC. var DeviceServiceCallbackClientName = di.TypeInstanceToName((*interfaces.DeviceServiceCallbackClient)(nil)) -// DeviceServiceCallbackClientFrom helper function queries the DIC and returns the DeviceServiceCallbackClientFrom instance. +// DeviceServiceCommandClientName contains the name of the DeviceServiceCommandClient instance in the DIC. +var DeviceServiceCommandClientName = di.TypeInstanceToName((*interfaces.DeviceServiceCommandClient)(nil)) + +// DeviceServiceCallbackClientFrom helper function queries the DIC and returns the DeviceServiceCallbackClient instance. func DeviceServiceCallbackClientFrom(get di.Get) interfaces.DeviceServiceCallbackClient { client, ok := get(DeviceServiceCallbackClientName).(interfaces.DeviceServiceCallbackClient) if !ok { @@ -22,3 +25,13 @@ func DeviceServiceCallbackClientFrom(get di.Get) interfaces.DeviceServiceCallbac return client } + +// DeviceServiceCommandClientFrom helper function queries the DIC and returns the DeviceServiceCommandClient instance. +func DeviceServiceCommandClientFrom(get di.Get) interfaces.DeviceServiceCommandClient { + client, ok := get(DeviceServiceCommandClientName).(interfaces.DeviceServiceCommandClient) + if !ok { + return nil + } + + return client +}