Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add migration M0007 for adding dependency injection #219

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading