The system allows services and repositories to be created in the main server definition and then store them in the context. They can then be retrieved and mapped onto the injection type and accessed in the handlers. The handlers can then use the deps to call services. Each service is initialized with the required repositories so they can be accessed directly.
16 lines
434 B
Go
16 lines
434 B
Go
package server
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
domain "github.com/haydenhargreaves/Potion/internal/domain/server"
|
|
)
|
|
|
|
// DepedencyInjectionMiddleware injects the dependencies into the context set. This is a middleware
|
|
// that is used to apply the required services.
|
|
func DepedencyInjectionMiddleware(deps *domain.InjectedDependencies) gin.HandlerFunc {
|
|
return func(ctx *gin.Context) {
|
|
ctx.Set("deps", deps)
|
|
ctx.Next()
|
|
}
|
|
}
|