Skip to content

Commit

Permalink
add migration M0007 for adding dependency injection
Browse files Browse the repository at this point in the history
  • Loading branch information
svenwltr committed Nov 15, 2024
1 parent 7d1b5ea commit 28a6e1d
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 28a6e1d

Please sign in to comment.