@@ -16,7 +16,7 @@ A module is a function that configures a set of related services. Modules can:
1616### Basic Module
1717
1818``` go
19- var DatabaseModule = godi.Module (" database" ,
19+ var DatabaseModule = godi.NewModule (" database" ,
2020 godi.AddSingleton (NewDatabaseConfig),
2121 godi.AddSingleton (NewDatabaseConnection),
2222 godi.AddScoped (NewUnitOfWork),
@@ -28,13 +28,13 @@ var DatabaseModule = godi.Module("database",
2828### Module with Dependencies
2929
3030``` go
31- var LoggingModule = godi.Module (" logging" ,
31+ var LoggingModule = godi.NewModule (" logging" ,
3232 godi.AddSingleton (NewLogConfig),
3333 godi.AddSingleton (NewLogger),
3434)
3535
36- var DatabaseModule = godi.Module (" database" ,
37- godi. AddModule ( LoggingModule) , // Depend on logging
36+ var DatabaseModule = godi.NewModule (" database" ,
37+ LoggingModule , // Depend on logging
3838 godi.AddSingleton (NewDatabaseConnection),
3939 godi.AddScoped (NewRepository),
4040)
@@ -87,31 +87,31 @@ func main() {
8787
8888``` go
8989// Core layer - no dependencies
90- var CoreModule = godi.Module (" core" ,
90+ var CoreModule = godi.NewModule (" core" ,
9191 godi.AddSingleton (NewConfig),
9292 godi.AddSingleton (NewLogger),
9393 godi.AddSingleton (NewMetrics),
9494)
9595
9696// Infrastructure layer - depends on core
97- var InfrastructureModule = godi.Module (" infrastructure" ,
98- godi. AddModule ( CoreModule) ,
97+ var InfrastructureModule = godi.NewModule (" infrastructure" ,
98+ CoreModule ,
9999 godi.AddSingleton (NewDatabase),
100100 godi.AddSingleton (NewCache),
101101 godi.AddSingleton (NewMessageQueue),
102102)
103103
104104// Domain layer - depends on infrastructure
105- var DomainModule = godi.Module (" domain" ,
106- godi. AddModule ( InfrastructureModule) ,
105+ var DomainModule = godi.NewModule (" domain" ,
106+ InfrastructureModule ,
107107 godi.AddScoped (NewUserService),
108108 godi.AddScoped (NewOrderService),
109109 godi.AddScoped (NewProductService),
110110)
111111
112112// API layer - depends on domain
113- var APIModule = godi.Module (" api" ,
114- godi. AddModule ( DomainModule) ,
113+ var APIModule = godi.NewModule (" api" ,
114+ DomainModule ,
115115 godi.AddScoped (NewUserController),
116116 godi.AddScoped (NewOrderController),
117117 godi.AddScoped (NewProductController),
@@ -122,48 +122,48 @@ var APIModule = godi.Module("api",
122122
123123``` go
124124// User feature module
125- var UserFeatureModule = godi.Module (" user-feature" ,
125+ var UserFeatureModule = godi.NewModule (" user-feature" ,
126126 godi.AddScoped (NewUserRepository),
127127 godi.AddScoped (NewUserService),
128128 godi.AddScoped (NewUserController),
129129 godi.AddSingleton (NewUserValidator),
130130)
131131
132132// Order feature module
133- var OrderFeatureModule = godi.Module (" order-feature" ,
133+ var OrderFeatureModule = godi.NewModule (" order-feature" ,
134134 godi.AddScoped (NewOrderRepository),
135135 godi.AddScoped (NewOrderService),
136136 godi.AddScoped (NewOrderController),
137137 godi.AddScoped (NewPaymentGateway),
138138)
139139
140140// Combine features
141- var ApplicationModule = godi.Module (" application" ,
142- godi. AddModule ( CoreModule) ,
143- godi. AddModule ( UserFeatureModule) ,
144- godi. AddModule ( OrderFeatureModule) ,
141+ var ApplicationModule = godi.NewModule (" application" ,
142+ CoreModule ,
143+ UserFeatureModule ,
144+ OrderFeatureModule ,
145145)
146146```
147147
148148### Environment-Specific Modules
149149
150150``` go
151151// Development module
152- var DevelopmentModule = godi.Module (" development" ,
152+ var DevelopmentModule = godi.NewModule (" development" ,
153153 godi.AddSingleton (func () Cache { return NewMemoryCache () }),
154154 godi.AddSingleton (func () Database { return NewSQLiteDB () }),
155155 godi.AddSingleton (func () EmailService { return NewMockEmailService () }),
156156)
157157
158158// Production module
159- var ProductionModule = godi.Module (" production" ,
159+ var ProductionModule = godi.NewModule (" production" ,
160160 godi.AddSingleton (func () Cache { return NewRedisCache () }),
161161 godi.AddSingleton (func () Database { return NewPostgresDB () }),
162162 godi.AddSingleton (func () EmailService { return NewSMTPEmailService () }),
163163)
164164
165165// Select module based on environment
166- func GetEnvironmentModule (env string ) func (ServiceCollection) error {
166+ func GetEnvironmentModule (env string ) func (godi. ServiceCollection) error {
167167 switch env {
168168 case " production" :
169169 return ProductionModule
@@ -181,7 +181,7 @@ func GetEnvironmentModule(env string) func(ServiceCollection) error {
181181
182182``` go
183183func DatabaseModuleWithConfig (dbConfig DatabaseConfig ) func (godi.ServiceCollection) error {
184- return godi.Module (" database" ,
184+ return godi.NewModule (" database" ,
185185 godi.AddSingleton (func () *DatabaseConfig { return &dbConfig }),
186186 godi.AddSingleton (NewDatabaseConnection),
187187 godi.AddScoped (NewRepository),
@@ -232,23 +232,23 @@ func APIModuleWithFeatures(features FeatureFlags) func(godi.ServiceCollection) e
232232
233233``` go
234234// Base modules
235- var LoggingModule = godi.Module (" logging" ,
235+ var LoggingModule = godi.NewModule (" logging" ,
236236 godi.AddSingleton (NewLogger),
237237)
238238
239- var MetricsModule = godi.Module (" metrics" ,
239+ var MetricsModule = godi.NewModule (" metrics" ,
240240 godi.AddSingleton (NewMetricsCollector),
241241)
242242
243- var TracingModule = godi.Module (" tracing" ,
243+ var TracingModule = godi.NewModule (" tracing" ,
244244 godi.AddSingleton (NewTracer),
245245)
246246
247247// Composite module
248- var ObservabilityModule = godi.Module (" observability" ,
249- godi. AddModule ( LoggingModule) ,
250- godi. AddModule ( MetricsModule) ,
251- godi. AddModule ( TracingModule) ,
248+ var ObservabilityModule = godi.NewModule (" observability" ,
249+ LoggingModule ,
250+ MetricsModule ,
251+ TracingModule ,
252252 godi.AddSingleton (NewObservabilityService),
253253)
254254```
@@ -258,7 +258,7 @@ var ObservabilityModule = godi.Module("observability",
258258### Test Module
259259
260260``` go
261- var TestModule = godi.Module (" test" ,
261+ var TestModule = godi.NewModule (" test" ,
262262 godi.AddSingleton (func () Database { return NewInMemoryDB () }),
263263 godi.AddSingleton (func () Cache { return NewMockCache () }),
264264 godi.AddSingleton (func () EmailService { return NewMockEmailService () }),
@@ -334,7 +334,7 @@ import (
334334 " myapp/internal/infrastructure/messaging"
335335)
336336
337- var InfrastructureModule = godi.Module (" infrastructure" ,
337+ var InfrastructureModule = godi.NewModule (" infrastructure" ,
338338 // Database
339339 godi.AddSingleton (database.NewConfig ),
340340 godi.AddSingleton (database.NewConnection ),
@@ -359,11 +359,11 @@ Each module should have a single, clear purpose:
359359
360360``` go
361361// ✅ Good - focused modules
362- var AuthModule = godi.Module (" auth" , ...)
363- var PaymentModule = godi.Module (" payment" , ...)
362+ var AuthModule = godi.NewModule (" auth" , ...)
363+ var PaymentModule = godi.NewModule (" payment" , ...)
364364
365365// ❌ Bad - mixed concerns
366- var UtilityModule = godi.Module (" utility" ,
366+ var UtilityModule = godi.NewModule (" utility" ,
367367 godi.AddSingleton (NewAuth),
368368 godi.AddSingleton (NewPayment),
369369 godi.AddSingleton (NewEmail),
@@ -376,7 +376,7 @@ Make module dependencies explicit:
376376
377377``` go
378378// ✅ Good - clear dependency chain
379- var AppModule = godi.Module (" app" ,
379+ var AppModule = godi.NewModule (" app" ,
380380 CoreModule , // Explicit dependency
381381 DatabaseModule , // Explicit dependency
382382 godi.AddScoped (NewAppService),
@@ -387,12 +387,12 @@ var AppModule = godi.Module("app",
387387
388388``` go
389389// ❌ Bad - circular dependency
390- var ModuleA = godi.Module (" A" ,
391- godi. AddModule ( ModuleB) , // A depends on B
390+ var ModuleA = godi.NewModule (" A" ,
391+ ModuleB , // A depends on B
392392)
393393
394- var ModuleB = godi.Module (" B" ,
395- godi. AddModule ( ModuleA) , // B depends on A - circular!
394+ var ModuleB = godi.NewModule (" B" ,
395+ ModuleA , // B depends on A - circular!
396396)
397397```
398398
@@ -410,7 +410,7 @@ var ModuleB = godi.Module("B",
410410// Dependencies:
411411// - CoreModule (for logging and configuration)
412412// - DatabaseModule (for user storage)
413- var AuthModule = godi.Module (" auth" ,
413+ var AuthModule = godi.NewModule (" auth" ,
414414 // ... registrations
415415)
416416```
@@ -438,7 +438,7 @@ func TestAuthModule(t *testing.T) {
438438### Web Application Module
439439
440440``` go
441- var WebModule = godi.Module (" web" ,
441+ var WebModule = godi.NewModule (" web" ,
442442 // Core web services
443443 godi.AddSingleton (NewRouter),
444444 godi.AddSingleton (NewMiddlewareChain),
@@ -460,7 +460,7 @@ var WebModule = godi.Module("web",
460460### Background Jobs Module
461461
462462``` go
463- var JobsModule = godi.Module (" jobs" ,
463+ var JobsModule = godi.NewModule (" jobs" ,
464464 // Job infrastructure
465465 godi.AddSingleton (NewJobScheduler),
466466 godi.AddSingleton (NewJobQueue),
0 commit comments