Skip to content

Commit 40b7b01

Browse files
committed
Update Readme
1 parent a26f527 commit 40b7b01

3 files changed

Lines changed: 58 additions & 40 deletions

File tree

.github/FUNDING.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/release.yml

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,40 @@ on:
55
inputs:
66
semver:
77
type: string
8-
description: 'Semver (eg: v1.2.3)'
8+
description: "Semver (eg: v1.2.3)"
99
required: true
1010

1111
jobs:
1212
release:
13-
if: github.triggering_actor == 'samber'
1413
runs-on: ubuntu-latest
1514
steps:
16-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v2
1716

18-
- name: Set up Go
19-
uses: actions/setup-go@v2
20-
with:
21-
go-version: 1.18
22-
stable: false
17+
- name: Set up Go
18+
uses: actions/setup-go@v2
19+
with:
20+
go-version: 1.18
21+
stable: false
2322

24-
- name: Test
25-
run: make test
23+
- name: Test
24+
run: make test
2625

27-
# remove tests in order to clean dependencies
28-
- name: Remove xxx_test.go files
29-
run: rm -rf *_test.go docker-compose.yml examples/
26+
# remove tests in order to clean dependencies
27+
- name: Remove xxx_test.go files
28+
run: rm -rf *_test.go docker-compose.yml examples/
3029

31-
- name: Cleanup dependencies
32-
run: go mod tidy
30+
- name: Cleanup dependencies
31+
run: go mod tidy
3332

34-
- name: List files
35-
run: tree -Cfi
36-
- name: Write new go.mod into logs
37-
run: cat go.mod
38-
- name: Write new go.sum into logs
39-
run: cat go.sum
33+
- name: List files
34+
run: tree -Cfi
35+
- name: Write new go.mod into logs
36+
run: cat go.mod
37+
- name: Write new go.sum into logs
38+
run: cat go.sum
4039

41-
- name: Create tag
42-
run: |
40+
- name: Create tag
41+
run: |
4342
git config --global user.name '${{ github.triggering_actor }}'
4443
git config --global user.email "${{ github.triggering_actor}}@users.noreply.github.com"
4544
@@ -48,8 +47,8 @@ jobs:
4847
git tag ${{ inputs.semver }}
4948
git push origin ${{ inputs.semver }}
5049
51-
- name: Release
52-
uses: softprops/action-gh-release@v1
53-
with:
54-
name: ${{ inputs.semver }}
55-
tag_name: ${{ inputs.semver }}
50+
- name: Release
51+
uses: softprops/action-gh-release@v1
52+
with:
53+
name: ${{ inputs.semver }}
54+
tag_name: ${{ inputs.semver }}

README.md

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# do - Dependency Injection
1+
# DI - Dependency Injection
2+
3+
> This is a forked of the original [Do](https://github.com/samber/do) package with an extension to allow dynamically injecting depdencies to a struct through reflection.
4+
25

3-
[![tag](https://img.shields.io/github/tag/samber/di.svg)](https://github.com/cryptoniumX/di/releases)
46
![Go Version](https://img.shields.io/badge/Go-%3E%3D%201.18-%23007d9c)
57
[![GoDoc](https://godoc.org/github.com/cryptoniumX/di?status.svg)](https://pkg.go.dev/github.com/cryptoniumX/di)
68
![Build Status](https://github.com/cryptoniumX/di/actions/workflows/test.yml/badge.svg)
@@ -12,15 +14,6 @@
1214

1315
This library implements the Dependency Injection design pattern. It may replace the `uber/dig` fantastic package in simple Go projects. `samber/do` uses Go 1.18+ generics and therefore is typesafe.
1416

15-
**See also:**
16-
17-
- [samber/lo](https://github.com/samber/lo): A Lodash-style Go library based on Go 1.18+ Generics
18-
- [samber/mo](https://github.com/samber/mo): Monads based on Go 1.18+ Generics (Option, Result, Either...)
19-
20-
**Why this name?**
21-
22-
I love **short name** for such a utility library. This name is the sum of `DI` and `Go` and no Go package currently uses this name.
23-
2417
## 💡 Features
2518

2619
- Service registration
@@ -43,6 +36,33 @@ I love **short name** for such a utility library. This name is the sum of `DI` a
4336

4437
🛑 Services can be shutdowned properly, in back-initialization order. Services implementing `di.Shutdownable` interface will be called via `di.Shutdown[type]()` or `Container.Shutdown()`.
4538

39+
## Di compared to original Do package
40+
We added a method to allow injecting dependencies dynamically through struct reflection.
41+
Declare a service, and add a `di:"<name>:` tag to the field where you want the container to inject the corresponding dependency.
42+
43+
```go
44+
// main.go
45+
container := New()
46+
repository := newRepository()
47+
redisClient := newRedisClient()
48+
ProvideValue[Repository](container, repository)
49+
ProvideValue[RedisClient](container, redisClient)
50+
51+
// service.go
52+
type service struct {
53+
Repository Repository `di:"repository"`
54+
RedisClient RedisClient `di:"redisClient"`
55+
}
56+
57+
func newService(
58+
container *di.Container
59+
) (&service, error) {
60+
s := service{}
61+
err := container.Inject(&s)
62+
return s, err
63+
}
64+
```
65+
4666
## 🚀 Install
4767

4868
```sh

0 commit comments

Comments
 (0)