wire icon indicating copy to clipboard operation
wire copied to clipboard

[Question] Is there a guice for build a singleton object?

Open Moln opened this issue 3 years ago • 0 comments

I had read the guide, but not found build the singleton example.

// wire.go
func InitializeFoo() *Foo {
    panic(wire.Build(NewFoo))
}

// wire_gen.go
func InitializeFoo() *Foo {
    return NewFoo()
}

// main.go
func main() {
  foo1 := InitializeFoo()
  foo2 := InitializeFoo()
  foo1 != foo2 //  How to build the singleton object?
}

Moln avatar Aug 21 '22 04:08 Moln