The following snippet declares two google/wire initializers which have a dependency in common. What is the best way to enforce that only one instance of the configuration is created?
I could pass the shared dependency down to the InitializeStorageHandler function, but that would defeat the purpose of DI if my understanding is correct.
Of course, I could also use the Singleton pattern. I'm not sure if this is the "Go-Way" of doing things. Is there a best practice?
package api
import (
"../storage"
"../config"
"github.com/google/wire"
)
func InitializeServer() (*Server, error) {
panic(wire.Build(config.NewConfiguration, NewServer))
}
func InitializeStorageHandler() *StorageHandler {
panic(wire.Build(config.NewConfiguration, storage.NewStorage, storage.NewService, NewStorageHandler))
}