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

Method AddModule

c.go:210–230  ·  view source on GitHub ↗

AddModule adds a module to the core. A Module is a group of functionality. It must provide some runnable stuff: http handlers, grpc handlers, cron jobs, one-time command, etc. Optionally if the module embeds di.In, its fields will be injected by DI container. The semantics of injection follows the

(module interface{})

Source from the content-addressed store, hash-verified

208// Note that the module added in this way will not retain any original field
209// values, i.e. the module will only contain fields populated by DI container.
210func (c *C) AddModule(module interface{}) {
211 t := reflect.TypeOf(module)
212 if t.Kind() == reflect.Ptr && dig.IsIn(t.Elem()) {
213 err := di.IntoPopulator(c.di).Populate(module)
214 if err != nil {
215 panic(err)
216 }
217 c.Container.AddModule(module)
218 return
219 }
220 if dig.IsIn(t) {
221 copy := reflect.New(t)
222 err := di.IntoPopulator(c.di).Populate(copy.Interface())
223 if err != nil {
224 panic(err)
225 }
226 c.Container.AddModule(copy.Elem().Interface())
227 return
228 }
229 c.Container.AddModule(module)
230}
231
232// Provide adds dependencies provider to the core. Note the dependency provider
233// must be a function in the form of:

Callers 15

provideMethod · 0.95
AddModuleFuncMethod · 0.95
Example_minimalFunction · 0.45
ExampleC_stackFunction · 0.45
TestC_ServeFunction · 0.45
TestC_ServeDisableFunction · 0.45
TestC_cleanupFunction · 0.45
TestContainer_ShutdownFunction · 0.45
TestC_AddModuleFunction · 0.45

Calls 2

IntoPopulatorFunction · 0.92
PopulateMethod · 0.65

Tested by 15

Example_minimalFunction · 0.36
ExampleC_stackFunction · 0.36
TestC_ServeFunction · 0.36
TestC_ServeDisableFunction · 0.36
TestC_cleanupFunction · 0.36
TestContainer_ShutdownFunction · 0.36
TestC_AddModuleFunction · 0.36
Example_modulesFunction · 0.36