module

Di::KeyParser

Shared key parsing utilities for Registry and Scope. Handles Crystal namespaced types (e.g. "NS::C:name") correctly.

Key format:

  • "Type" → default concrete registration
  • "Type:name" → named concrete registration
  • "~Type:Impl" → interface binding (unnamed)
  • "~Type:Impl:name" → interface binding (named)

The "~" prefix ensures interface bindings don't leak into concrete resolution.

Constants

INTERFACE_PREFIX = "~"

Marker prefix for interface binding keys.

Instance methods

interface_prefix(interface_type : String) : String

Build interface lookup prefix for scanning.

Source
key(type : String, impl : String | Nil = nil, name : String | Nil = nil) : String

Build a registry key from segments joined by ':'. key(type: "Type") → "Type" key(type: "Type", name: "primary") → "Type:primary" key(type: "Type", impl: "Impl") → "~Type:Impl" key(type: "Type", impl: "Impl", name: "primary") → "~Type:Impl:primary"

Source
parse_key(key : String) : Tuple(String, String | Nil)

Parse a registry key into (type_name, service_name) tuple. Finds the first single ':' that isn't part of '::' namespace separator. Strips interface marker from type_name if present.

Source
resolve_ambiguous(matches : Array(Provider::Base), interface_type : String, name : String) : Provider::Base

Check for ambiguous named matches and return single provider or raise.

Source
resolve_ambiguous?(matches : Array(Provider::Base), interface_type : String) : Provider::Base | Nil

Like resolve_ambiguous, but returns nil instead of raising ServiceNotFound.

Source