MCPcopy Create free account
hub / github.com/alecthomas/inject / Singleton

Function Singleton

annotations.go:135–137  ·  view source on GitHub ↗

Singleton annotates a provider function to indicate that the provider will only be called once, and that its return value will be used for all subsequent retrievals of the given type. count := 0 injector.Bind(Singleton(func() int { count++ return 123 })) injector.Get(reflect.TypeOf(1)

(v interface{})

Source from the content-addressed store, hash-verified

source not stored for this graph (policy: none)

Callers 4

TestSingletonAnnotationFunction · 0.85
TestSequenceAnnotationFunction · 0.85
InstallMethod · 0.85

Calls

no outgoing calls

Tested by 3

TestSingletonAnnotationFunction · 0.68
TestSequenceAnnotationFunction · 0.68