https://github.com/matzefriedrich/parsley
An easy-to-use reflection-based dependency injection package that fits into any Go application.
https://github.com/matzefriedrich/parsley
dependency-injection go golang inversion-of-control reflection service-factory service-locator
Last synced: 12 months ago
JSON representation
An easy-to-use reflection-based dependency injection package that fits into any Go application.
- Host: GitHub
- URL: https://github.com/matzefriedrich/parsley
- Owner: matzefriedrich
- License: apache-2.0
- Created: 2024-07-09T22:11:54.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-10T18:03:54.000Z (over 1 year ago)
- Last Synced: 2025-03-18T13:16:01.663Z (over 1 year ago)
- Topics: dependency-injection, go, golang, inversion-of-control, reflection, service-factory, service-locator
- Language: Go
- Homepage: https://matzefriedrich.github.io/parsley-docs/
- Size: 237 KB
- Stars: 23
- Watchers: 3
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - matzefriedrich/parsley - to-use reflection-based dependency injection package that fits into any Go application. ☆`31` (Miscellaneous / Dependency Injection)
- fucking-awesome-go - parsley - A flexible and modular reflection-based DI library with advanced features like scoped contexts and proxy generation, designed for large-scale Go applications. (Miscellaneous / Dependency Injection)
- awesome-go - parsley - A flexible and modular reflection-based DI library with advanced features like scoped contexts and proxy generation, designed for large-scale Go applications. (Miscellaneous / Dependency Injection)
- awesome-go-cn - parsley - based DI library with advanced features like scoped contexts and proxy generation, designed for large-scale Go applications. [![godoc][D]](https://godoc.org/github.com/matzefriedrich/parsley) (杂项 / 依赖注入)
- awesome-go-with-stars - parsley - based DI library with advanced features like scoped contexts and proxy generation, designed for large-scale Go applications. | 2026-06-12 | (Microsoft Office / Dependency Injection)
- awesome-go-cn - parsley - based DI library with advanced features like scoped contexts and proxy generation, designed for large-scale Go applications. [![godoc][D]](https://godoc.org/github.com/matzefriedrich/parsley) (杂项 / 依赖注入)
README
[](https://github.com/matzefriedrich/parsley/actions/workflows/go.yml)
[](https://coveralls.io/github/matzefriedrich/parsley)
[](https://pkg.go.dev/github.com/matzefriedrich/parsley)
[](https://goreportcard.com/report/github.com/matzefriedrich/parsley)



[](https://app.fossa.com/projects/custom%2B48327%2Fgithub.com%2Fmatzefriedrich%2Fparsley?ref=badge_shield&issueType=license)
[](https://app.fossa.com/projects/custom%2B48327%2Fgithub.com%2Fmatzefriedrich%2Fparsley?ref=badge_shield&issueType=security)
## What is Parsley?
Parsley is a reflection-based dependency injection (DI) package for Go that streamlines dependency management through automated lifetime management, type-safe registration, service resolution and activation, proxy generation, and method interception. It leverages reflection only at startup, ensuring runtime efficiency, and supports features like mocking and testing integration for better development workflows.
### Why use dependency injection in Go?
Dependency injection in Go typically relies on constructor functions, which are idiomatic and foundational for creating and managing dependencies. While this approach is powerful, it can lead to boilerplate code as projects become more complex, requiring explicit instantiation and manual wiring. Addionally, more sophisticated ramp-up code is needed, if not all instances shall be created at application start. Parsley eliminates much of this repetitive code by automating the creation and wiring of dependencies, enabling developers to focus on application logic. It aims to enhance modularity and make managing dependencies easier.
## Key Features
- **Type Registration**: Supports constructor functions, lifetime management (singleton, scoped, transient), and safe casts.
- **Modular and Lazy Loading**: Register types as modules, resolve dependencies on-demand, and inject lazily with `Lazy[T]`.
- **Registration Validation**: Ensures early detection of missing registrations or circular dependencies.
- **Advanced Registrations**: Register multiple implementations for the same interface using named services or lists.
- **Proxy and Mock Support**: Generate extensible proxy types and configurable mocks to streamline testing workflows.
For a complete overview of features and capabilities, refer to the [Parsley documentation](https://matzefriedrich.github.io/parsley-docs/).
## Usage
### Install Parsley
Add Parsley to your project:
```sh
go get github.com/matzefriedrich/parsley
```
For advanced features like proxy generation or mock creation, install the `parsley-cli` utility:
```sh
go install github.com/matzefriedrich/parsley/cmd/parsley-cli
```
---
Copyright 2024 - 2025 by Matthias Friedrich