I am having little trouble with correct configuration of wire I have following setup
Router
func NewRouter(routes []RouterPath) AppRouter {
r := &appRouter{
routes: routes,
}
return r
}
Router interface
type RouterPath interface {
Register(root *mux.Router) (p *mux.Router)
}
and i do have few controllers that implement this interface currently the best way how i find out how to make wire to solve DI was this
var routersSet = wire.NewSet(
routers.NewAuth,
routers.NewRoot,
routers.NewUser,
routers.NewPhpInfo,
)
func RouterProvider(info *routers.PhpInfo, root *routers.Root, user *routers.User) web.AppRouter {
routes := []web.RouterPath{
info,
root,
user,
}
return routers.NewRouter(routes)
}
func Init() Kernel {
wire.Build(
routersSet,
RouterProvider,
NewKernel,
)
return nil
}
what i have problem with is that i had to make transition layer to NewRouter because it expects array of routes. Which will grow very easily and method definition will be horible to maintain. I would love to see smtg like put wire.ProviderSet into array and use that as a parameter of NewRouter but i could not figure how to do this.
Is there any better approach instead of this ?