Package github.com/MY-RV/goxdi.
This page lists the public surface. For behavior and guidance, use the guides linked below.
| Topic | Guide |
|---|---|
| Concepts | Overview |
| First program | Getting started |
Add* |
Registering services |
| Lifetimes | Lifetimes |
Scope / Close |
Scopes |
Get / MustGet |
Resolving |
| Sentinels | Errors |
| Name | Definition |
|---|---|
Lifetime |
int — retention policy for a registration |
Factory[T any] |
func(Resolver) (T, error) |
Resolver |
resolve target for Get / MustGet |
Builder |
mutable registrations before Build |
Container |
root container; owns singletons |
Scope |
child lifetime; owns scoped instances |
const (
Singleton Lifetime = iota
Scoped
Transient
)Lifetime.String() returns "Singleton", "Scoped", "Transient", or "Unknown".
func NewBuilder() *Builder
func (b *Builder) Build() *Container
func AddSingleton[T any](b *Builder, factory Factory[T]) error
func AddScoped[T any](b *Builder, factory Factory[T]) error
func AddTransient[T any](b *Builder, factory Factory[T]) error
func (c *Container) NewScope() *Scope
func (c *Container) Close() error
func (s *Scope) NewScope() *Scope
func (s *Scope) Close() error
func Get[T any](from Resolver) (T, error)
func MustGet[T any](from Resolver) TContainer and Scope implement Resolver.
var (
ErrNotRegistered error
ErrScopeRequired error
ErrClosed error
ErrScopeClosed error // alias of ErrClosed
ErrAlreadyRegistered error
ErrCircularDependency error
)