This document covers the dependency injection system and global configuration mechanisms in the Solid::Process framework. It explains how to configure default base classes for inputs and dependencies, how to define and inject dependencies into processes, and how the framework validates dependency interfaces.
For information about input validation and data modeling patterns, see Input and Data Modeling. For details about the core process execution flow, see Solid::Process - The Core Abstraction.
The Solid::Process framework provides a global configuration system through the Solid::Process::Config class that allows customization of default base classes for inputs and dependencies.
Sources: lib/solid/process/config.rb1-35 lib/solid/process/class_methods.rb1-42
The configuration system uses a singleton pattern where Config.instance provides the global configuration object. The SolidModel lambda validates that configured classes include the Solid::Model module.
The framework provides several methods for accessing and modifying configuration:
| Method | Purpose | Example Usage |
|---|---|---|
Solid::Process.config | Access current configuration | Solid::Process.config.input_class |
Solid::Process.configuration | Configure with block | `Solid::Process.configuration { |
Solid::Process.configure | Alias for configuration | Same as above |
Sources: test/solid/process/config_test.rb14-42
The dependency injection system allows processes to declare external dependencies that can be validated and customized for different environments.
Sources: lib/solid/process/class_methods.rb11-37
Dependencies are defined using either the dependencies method with a block, or by assigning a pre-existing class using dependencies=. The framework automatically creates a Dependencies constant within the process class.
Dependencies can validate their own interfaces to ensure they provide required methods:
Sources: test/support/040_user_creation_with_dependencies.rb7-12
The framework commonly uses the repository pattern for database dependencies:
| Component | Responsibility | Implementation |
|---|---|---|
dependencies.repository | Data access interface | Default: ::User |
| Interface validation | Ensures required methods | respond_to?(:create!), respond_to?(:exists?) |
| Default values | Fallback implementations | default: ::User |
Sources: test/support/040_user_creation_with_dependencies.rb4-13
The ClassMethods module provides the DSL for defining inputs and dependencies within process classes.
Sources: lib/solid/process/class_methods.rb11-20
Sources: lib/solid/process/class_methods.rb28-36
You can configure custom base classes for inputs and dependencies globally:
Sources: test/solid/process/config_test.rb44-96
The framework supports two patterns for defining dependencies and inputs:
| Pattern | Usage | When to Use |
|---|---|---|
| Class Assignment | self.deps = MyDepsClass | Pre-existing, reusable dependency classes |
| Block Definition | deps { attribute :repo } | Process-specific, inline definitions |
Sources: test/solid/process/dependencies/assignment_alias_test.rb10-23
The framework provides convenient aliases for common operations:
| Primary Method | Alias | Purpose |
|---|---|---|
dependencies | deps | Shorter syntax for dependency access |
dependencies= | deps= | Shorter syntax for dependency assignment |
dependencies_class | deps_class | Configuration alias |
Sources: lib/solid/process/class_methods.rb39-40 lib/solid/process/config.rb26-27
The framework supports both patterns - processes with external dependencies and self-contained processes:
Sources: test/support/040_user_creation_with_dependencies.rb1-61 test/support/030_user_creation_without_deps.rb1-50
Dependencies support the full validation framework available to Solid::Input:
| Validation Type | Example | Purpose |
|---|---|---|
| Presence | validates :repository, presence: true | Ensure required dependencies |
| Custom validation | validate :repository_interface | Interface compliance checking |
| Format validation | validates :api_key, format: {...} | String format requirements |
Sources: test/support/040_user_creation_with_dependencies.rb7-12
Refresh this wiki