From 0bef608297d7def2a18d054e7230fe0e0a3710a7 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 12 Apr 2025 18:11:05 -0600 Subject: refactor: extract mountable interface to allow controllers to mount themselves into the mux --- app/init.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/init.go (limited to 'app/init.go') diff --git a/app/init.go b/app/init.go new file mode 100644 index 0000000..e48713d --- /dev/null +++ b/app/init.go @@ -0,0 +1,25 @@ +package app + +import ( + "net/http" + + "github.com/xlgmokha/x/pkg/ioc" + "gitlab.com/mokhax/sparkled/app/controllers/health" + "gitlab.com/mokhax/sparkled/app/controllers/sparkles" + "gitlab.com/mokhax/sparkled/pkg/db" +) + +func init() { + ioc.RegisterSingleton[db.Repository](ioc.Default, func() db.Repository { + return db.NewRepository() + }) + ioc.RegisterSingleton[*http.ServeMux](ioc.Default, func() *http.ServeMux { + return http.NewServeMux() + }) + ioc.Register[*sparkles.Controller](ioc.Default, func() *sparkles.Controller { + return sparkles.New(ioc.MustResolve[db.Repository](ioc.Default)) + }) + ioc.Register[*health.Controller](ioc.Default, func() *health.Controller { + return health.New() + }) +} -- cgit v1.2.3