Potion/internal/app/server/middleware.go
Hayden Hargreaves 71e32f1fd7 (FIX): Created a decent dependency inject architecture.
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.
2025-06-14 12:30:17 -07:00

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()
}
}