#
Welcome to Parsley
In
Parsley is an easy-to-use, reflection-based dependency injection package that fits seamlessly into any Go application. It bridges the gap between dependency configuration and service activation, providing automated lifetime management and a clean, organized way to handle dependencies.
#
Key Features
#
Type Registration & Resolution
- Constructor Functions: Register types via constructor functions and automatically inject dependencies into constructors.
- Resolve by Type: Support for both interfaces and pointer types.
- Safe Casting: Use
ResolveRequiredService[T]
for type-safe resolutions. - Lifetime Management: Register types with singleton, scoped, or transient lifetimes.
- Validate Service Registrations: Parsley now includes built-in validation for service registrations, prevent runtime errors due to missing or circular dependencies.
#
Advanced Registrations
- Modular Registrations: Bundle registrations into modules for cleaner organization.
- Lazy Loading: Dependencies are injected only when needed using
Lazy[T]
. - Custom Factories: Define custom factory functions for dynamic resolution.
- Provide to service instance to the resolver: Provide service instances to the resolver that cannnot be automatically constructed.
#
Multiple Registrations
- Named Services: Register and resolve multiple services for the same interface.
- Service Lists: Resolve services as a list.
#
Proxy & Mocking Support
- Proxy Services: Generate proxies as drop-in replacements with method interception.
- Mock Generation: Create configurable mocks to enhance testing.
Want to know more? Read on to discover how Parsley can enhance your Go application's architecture and maintainability.