MCPcopy Index your code
hub / github.com/DoNewsCode/core / ExampleC_AddModule_inject

Function ExampleC_AddModule_inject

example_test.go:43–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41}
42
43func ExampleC_AddModule_inject() {
44 type Foo struct {
45 di.In
46 Logger log.Logger
47 }
48 var f Foo
49 c := core.New()
50 c.Provide(di.Deps{func() log.Logger {
51 return log.NewLogfmtLogger(os.Stdout)
52 }})
53 // If the module embeds di.In (directly or indirectly via pointer), then DI will
54 // populate its fields.
55 c.AddModule(&f)
56 f.Logger.Log("msg", "hello")
57 // Output:
58 // msg=hello
59}
60
61func ExampleC_Provide() {
62 type Foo struct {

Callers

nothing calls this directly

Calls 4

NewFunction · 0.92
ProvideMethod · 0.80
LogMethod · 0.80
AddModuleMethod · 0.45

Tested by

no test coverage detected