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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.1
github.com/edgexfoundry/go-mod-core-contracts/v2 v2.0.0-dev.6
github.com/edgexfoundry/go-mod-registry/v2 v2.0.0-dev.1
github.com/edgexfoundry/go-mod-secrets/v2 v2.0.0-dev.2
github.com/gorilla/mux v1.7.1
Expand Down
19 changes: 19 additions & 0 deletions v2/bootstrap/container/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Copyright (C) 2021 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

package container

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

)

// 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


// 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

}
27 changes: 27 additions & 0 deletions v2/bootstrap/container/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Copyright (C) 2021 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

package container

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

// DataEventClientName contains the name of the EventClient instance in the DIC.
var DataEventClientName = "V2DataEventClient"

// DataReadingClientName contains the name of the ReadingClient instance in the DIC.
var DataReadingClientName = "V2DataReadingClient"

// DataEventClientFrom helper function queries the DIC and returns the EventClient instance.
func DataEventClientFrom(get di.Get) v2Clients.EventClient {
return get(DataEventClientName).(v2Clients.EventClient)
}

// DataReadingClientFrom helper function queries the DIC and returns the ReadingClient instance.
func DataReadingClientFrom(get di.Get) v2Clients.ReadingClient {
return get(DataReadingClientName).(v2Clients.ReadingClient)
}
19 changes: 19 additions & 0 deletions v2/bootstrap/container/deviceservice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Copyright (C) 2021 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

package container

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

// DeviceServiceCallbackClientName contains the name of the DeviceServiceCallbackClient instance in the DIC.
var DeviceServiceCallbackClientName = "V2DeviceServiceCallbackClient"

// DeviceServiceCallbackClientFrom helper function queries the DIC and returns the DeviceServiceCallbackClientFrom instance.
func DeviceServiceCallbackClientFrom(get di.Get) v2Clients.DeviceServiceCallbackClient {
return get(DeviceServiceCallbackClientName).(v2Clients.DeviceServiceCallbackClient)
}
43 changes: 43 additions & 0 deletions v2/bootstrap/container/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Copyright (C) 2021 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

package container

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

// MetadataDeviceClientName contains the name of the Metadata DeviceClient instance in the DIC.
var MetadataDeviceClientName = "V2MetadataDeviceClient"

// MetadataDeviceProfileClientName contains the name of the Metadata DeviceProfileClient instance in the DIC.
var MetadataDeviceProfileClientName = "V2MetadataDeviceProfileClient"

// MetadataDeviceServiceClientName contains the name of the Metadata DeviceServiceClient instance in the DIC.
var MetadataDeviceServiceClientName = "V2MetadataDeviceServiceClient"

// MetadataProvisionWatcherClientName contains the name of the Metadata ProvisionWatcherClient instance in the DIC.
var MetadataProvisionWatcherClientName = "V2MetadataProvisionWatcherClient"

// MetadataDeviceClientFrom helper function queries the DIC and returns the Metadata DeviceClient instance.
func MetadataDeviceClientFrom(get di.Get) v2Clients.DeviceClient {
return get(MetadataDeviceClientName).(v2Clients.DeviceClient)
}

// MetadataDeviceProfileClientFrom helper function queries the DIC and returns the Metadata DeviceProfileClient instance.
func MetadataDeviceProfileClientFrom(get di.Get) v2Clients.DeviceProfileClient {
return get(MetadataDeviceProfileClientName).(v2Clients.DeviceProfileClient)
}

// MetadataDeviceServiceClientFrom helper function queries the DIC and returns the Metadata DeviceServiceClient instance.
func MetadataDeviceServiceClientFrom(get di.Get) v2Clients.DeviceServiceClient {
return get(MetadataDeviceServiceClientName).(v2Clients.DeviceServiceClient)
}

// MetadataProvisionWatcherClientFrom helper function queries the DIC and returns the Metadata ProvisionWatcherClient instance.
func MetadataProvisionWatcherClientFrom(get di.Get) v2Clients.ProvisionWatcherClient {
return get(MetadataProvisionWatcherClientName).(v2Clients.ProvisionWatcherClient)
}