contract

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 0 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package contract defines the backend-agnostic dependency-injection contract used by the provider manager: the Container interface plus the neutral bind and resolve options.

The contract is deliberately free of any concrete container's types so that adapters (github.com/danceable/provider/adapters/...) can translate it onto different backends. It lives under internal/ purely to break an import cycle: the provider package re-exports every name here as provider.Container, provider.BindOption, provider.WithName, and so on, so callers never import this package directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BindOption

type BindOption func(*BindOptions)

BindOption is a functional option for configuring a binding.

func Lazy

func Lazy() BindOption

Lazy defers the resolver invocation until the first time the binding is resolved.

func Singleton

func Singleton() BindOption

Singleton marks the binding as a singleton (one shared instance).

func WithName

func WithName(name string) BindOption

WithName sets a name for the binding, enabling multiple concretes per abstraction.

type BindOptions

type BindOptions struct {
	// Name enables multiple concretes per abstraction, disambiguated by name.
	Name string

	// Singleton marks the binding as a single shared instance.
	Singleton bool

	// Lazy defers the resolver invocation until the first resolution.
	Lazy bool
}

BindOptions holds the neutral configuration for a single binding. Adapters read these fields and translate them into their backend's own bind calls; an adapter whose backend lacks a concept — one whose bindings are always lazy and memoized, say — may ignore the corresponding field.

func ApplyBindOptions

func ApplyBindOptions(opts ...BindOption) *BindOptions

ApplyBindOptions collects the given bind options into a BindOptions value. Adapters use it to read the neutral configuration before mapping it onto their backend.

type Container

type Container interface {
	// Reset deletes all the existing bindings.
	Reset()

	// Bind maps the type a resolver function returns to that resolver.
	Bind(receiver any, opts ...BindOption) error

	// Call invokes a function, resolving its arguments from the container.
	Call(receiver any, opts ...ResolveOption) error

	// Resolve fills a pointer with the concrete bound to the type it points to.
	Resolve(abstraction any, opts ...ResolveOption) error

	// Fill resolves the fields of a struct that carry the container tag.
	Fill(receiver any, opts ...ResolveOption) error

	// Scope returns a named child container, reused on later calls with that name.
	Scope(name string) Container

	// Derive returns an anonymous child container, collected once it is dropped.
	Derive() Container
}

Container defines the interface for a dependency injection container. It is a neutral surface: each adapter maps these methods and options onto the calls of the container it wraps.

type ResolveOption

type ResolveOption func(*ResolveOptions)

ResolveOption is a functional option for resolve-time parameters.

func WithParams

func WithParams(params ...any) ResolveOption

WithParams provides runtime values used to satisfy resolver arguments.

func WithResolveName

func WithResolveName(name string) ResolveOption

WithResolveName selects the named binding to resolve.

type ResolveOptions

type ResolveOptions struct {
	// Name selects a named binding to resolve.
	Name string

	// Params supplies runtime values used to satisfy resolver arguments.
	Params []any
}

ResolveOptions holds the neutral resolve-time parameters.

func ApplyResolveOptions

func ApplyResolveOptions(opts ...ResolveOption) *ResolveOptions

ApplyResolveOptions collects the given resolve options into a ResolveOptions value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL