Documentation
¶
Overview ¶
Package dependency provides an effect for interface-based dependency resolution using runtime duck typing.
A handler can register a list of objects. When an effect is performed, the handler attempts to match the requested interface type against its registered dependencies. If a match is found, the handler delegates the method call using the provided Quacker implementation. Otherwise, the request is delegated upward through the context chain.
This enables dynamic, testable, and scoped dependency injection without using global containers or code generation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Effect ¶
Effect performs a resumable dependency resolution effect. The generic type parameter D should be the interface type to match.
The given Quacker will be invoked against a matched dependency that implements D. If no handler exists in the context, the call panics unless recovered via delegateDependencyEffect.
func WithEffectHandler ¶
func WithEffectHandler( pctx context.Context, bufferSize int, dependencies []any, ) (context.Context, func() context.Context)
WithEffectHandler registers a dependency effect handler into the context. The handler can resolve method calls dynamically by matching interface types (duck) to the given list of concrete dependency objects.
Each time a matching dependency is found, the provided Quacker will be invoked with that object as the receiver.
This allows dynamic, runtime dependency injection for interface-based dispatch.
Returns the new context and a teardown function to remove the handler.
Types ¶
type Quacker ¶
type Quacker interface {
WithReceiver(receiver any) Quacker
Quack(ctx context.Context) (any, error)
}
Quacker represents an abstraction for deferred method invocation. It encapsulates a parsed method signature and arguments, and provides a way to dynamically invoke that method on a given receiver.