Skip to content

Commit

Permalink
Merge pull request #219 from rebuy-de/m0007
Browse files Browse the repository at this point in the history
add migration M0007 for adding dependency injection
  • Loading branch information
svenwltr authored Nov 15, 2024
2 parents 2aee19c + 28a6e1d commit 60c9250
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,43 @@
This file contains a list of tasks that are either required or at least
strongly recommended to align projects using this SDK.

## M0007 2024-11-08 Switch to Dependency Injection

### Reasoning

Our previous approach to have a single `Server` struct and to put all logic there gets messy pretty fast. Worse than
that it is hard to refactor this to separate this into multiple structs or packages. Dependency injection will help us
to separate those things in the very beginning of a project without manual wiring of dependencies.

### Hints

* The primary server.Run function should be replaced with a standalone `RunServer(ctx context.Context, c *dig.Container) error`
* The `cmdutil.Runner` should setup environment specific dependencies (eg Redis vs Miniredis) while `RunServer` should
setup the independent ones (eg services, workers and handlers).

### Examples

The `RunServer` function could look like this:

```go
func RunServer(ctx context.Context, c *dig.Container) error {
return errors.Join(
// define services and repos
c.Provide(...),

// define HTTP handlers
webutil.ProvideHandler(c, handlers.New...),

// define workers
runutil.ProvideWorker(c, workers.New...),

// start all workers
runutil.RunProvidedWorkers(ctx, c),
)
}
```


## M0006 2024-09-20 Use webutil.NewServer

### Reasoning
Expand Down

0 comments on commit 60c9250

Please sign in to comment.