Module Reference
Coming Soon — This feature is not yet implemented.
The Module Reference provides a way to access providers from other modules, retrieve the current module instance, or interact with the internal module system.
Planned Design
// Planned API (subject to change)
type ModuleRef struct {
container map[reflect.Type]interface{}
}
func (r *ModuleRef) Get(instance interface{}) error {
// Resolve a provider from the container
return nil
}
func (r *ModuleRef) Resolve(key string) interface{} {
// Resolve a named provider
return nil
}
Current Alternative
Import the module that exports the provider you need, then declare that provider
as a constructor dependency. Module providers are private by default; only
providers listed by Exports() are available to importing modules.
// CacheModule and ConfigModule must export *cache.Cache and *config.Config.
// Import both modules into the module that declares NewUserService.
func NewUserService(
repo *UserRepository,
cache *cache.Cache,
config *config.Config,
) *UserService {
return &UserService{
repo: repo,
cache: cache,
config: config,
}
}
Use Cases
| Use Case | Status |
|---|---|
| Access exported providers from imported modules | ✅ Available via DI container |
| Retrieve module instance | ⏳ Planned |
| Dynamic provider resolution | ⏳ Planned |
| Named/qualified bindings | ⏳ Planned |
Coming Soon
A formal ModuleRef API with named bindings and dynamic resolution is planned.