resolve

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContainerField

type ContainerField struct {
	Name   string
	Type   types.Type
	Inject InjectTag
}

ContainerField represents an injectable field in a Container struct.

Note: - Name can be "_" for override-only fields. - Type is the type to be provided (e.g. service.User, infra.Database).

func ConvertContainerFields

func ConvertContainerFields(c scan.ContainerSpec) ([]ContainerField, error)

ConvertContainerFields converts a scanned ContainerSpec into resolve-ready fields.

Resolution target rules:

  • If the Container has at least one `inject`-marked *public field* (non-blank), only those marked fields are included.
  • Blank fields ("_") are treated as provider overrides and do NOT switch the container into explicit mode. They are included only when they are `inject`-marked.

type Graph

type Graph struct {
	Roots []*Node
}

Graph represents a resolved dependency graph.

func BuildGraph

func BuildGraph(fields []ContainerField, providers []*Provider) (*Graph, error)

BuildGraph resolves dependencies starting from container fields.

type InjectTag

type InjectTag struct {
	// Provider selects a specific provider function by name.
	// Example: `inject:"provider:service.NewUser"`
	Provider string
}

InjectTag is a parsed `inject` struct tag for Container fields.

type Node

type Node struct {
	Provider *Provider
	Deps     []*Node
}

Node represents a node in the resolved dependency graph.

Each node corresponds to exactly one Provider. Nodes may be shared across the graph to represent a DAG (i.e. the same Provider can be depended on by multiple parents).

type Provider

type Provider struct {
	PkgPath     string
	Name        string
	NameWithPkg string
	ResultType  types.Type
	ReturnError bool
	Params      []types.Type
	Position    string
}

Provider represents a constructor function that can produce a value for dependency injection.

A Provider is identified by its identity (pointer equality), not by value. It is treated as immutable during resolution and is shared across the dependency graph for cycle detection and override resolution.

func ConvertProviders

func ConvertProviders(ps []scan.ProviderSpec) ([]*Provider, error)

ConvertProviders converts scanned ProviderDecl into resolve Provider nodes.

func OrderProviders

func OrderProviders(g *Graph) ([]*Provider, error)

OrderProviders returns providers in topological order (dependencies first). Providers may appear only once even if referenced multiple times by roots.

Jump to

Keyboard shortcuts

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