Skip to content

🎧 Your Personal Streaming Service

Simplified DI resolution

Deluanf4c1dbdd3c86
diff --git a/api/browsing.go b/api/browsing.go
index e9057e836..1c3b4485c 100644
--- a/api/browsing.go
+++ b/api/browsing.go
@@ -7,7 +7,6 @@ import (
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/engine"
"github.com/deluan/gosonic/utils"
- "github.com/karlkfi/inject"
)
type BrowsingController struct {
@@ -16,7 +15,7 @@ type BrowsingController struct {
}
func (c *BrowsingController) Prepare() {
- inject.ExtractAssignable(utils.Graph, &c.browser)
+ utils.ResolveDependencies(&c.browser)
}
func (c *BrowsingController) GetMediaFolders() {
diff --git a/api/get_album_list.go b/api/get_album_list.go
index 373490f74..6a5636e68 100644
--- a/api/get_album_list.go
+++ b/api/get_album_list.go
@@ -8,7 +8,6 @@ import (
"github.com/deluan/gosonic/domain"
"github.com/deluan/gosonic/engine"
"github.com/deluan/gosonic/utils"
- "github.com/karlkfi/inject"
)
type GetAlbumListController struct {
@@ -20,7 +19,7 @@ type GetAlbumListController struct {
type strategy func(offset int, size int) (*domain.Albums, error)
func (c *GetAlbumListController) Prepare() {
- inject.ExtractAssignable(utils.Graph, &c.listGen)
+ utils.ResolveDependencies(&c.listGen)
c.types = map[string]strategy{
"random": func(o int, s int) (*domain.Albums, error) { return c.listGen.GetRandom(o, s) },
diff --git a/api/get_cover_art.go b/api/get_cover_art.go
index 436fb4031..baed8f3f4 100644
--- a/api/get_cover_art.go
+++ b/api/get_cover_art.go
@@ -5,7 +5,6 @@ import (
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/engine"
"github.com/deluan/gosonic/utils"
- "github.com/karlkfi/inject"
)
type GetCoverArtController struct {
@@ -14,7 +13,7 @@ type GetCoverArtController struct {
}
func (c *GetCoverArtController) Prepare() {
- inject.ExtractAssignable(utils.Graph, &c.cover)
+ utils.ResolveDependencies(&c.cover)
}
func (c *GetCoverArtController) Get() {
diff --git a/api/playlists.go b/api/playlists.go
index 40f0bc57c..880fa08d0 100644
--- a/api/playlists.go
+++ b/api/playlists.go
@@ -5,7 +5,6 @@ import (
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/engine"
"github.com/deluan/gosonic/utils"
- "github.com/karlkfi/inject"
)
type PlaylistsController struct {
@@ -14,7 +13,7 @@ type PlaylistsController struct {
}
func (c *PlaylistsController) Prepare() {
- inject.ExtractAssignable(utils.Graph, &c.pls)
+ utils.ResolveDependencies(&c.pls)
}
func (c *PlaylistsController) GetAll() {
diff --git a/api/searching.go b/api/searching.go
index 1bf35a62c..0f98af453 100644
--- a/api/searching.go
+++ b/api/searching.go
@@ -5,7 +5,6 @@ import (
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/engine"
"github.com/deluan/gosonic/utils"
- "github.com/karlkfi/inject"
)
type SearchingController struct {
@@ -14,7 +13,7 @@ type SearchingController struct {
}
func (c *SearchingController) Prepare() {
- inject.ExtractAssignable(utils.Graph, &c.search)
+ utils.ResolveDependencies(&c.search)
}
func (c *SearchingController) Search2() {
diff --git a/api/stream.go b/api/stream.go
index 60c64cb3c..1893da3b0 100644
--- a/api/stream.go
+++ b/api/stream.go
@@ -6,7 +6,6 @@ import (
"github.com/deluan/gosonic/domain"
"github.com/deluan/gosonic/engine"
"github.com/deluan/gosonic/utils"
- "github.com/karlkfi/inject"
)
type StreamController struct {
@@ -17,7 +16,7 @@ type StreamController struct {
}
func (c *StreamController) Prepare() {
- inject.ExtractAssignable(utils.Graph, &c.repo)
+ utils.ResolveDependencies(&c.repo)
c.id = c.RequiredParamString("id", "id parameter required")
diff --git a/scanner/importer.go b/scanner/importer.go
index c230c4763..f767d1bd0 100644
--- a/scanner/importer.go
+++ b/scanner/importer.go
@@ -27,14 +27,8 @@ func StartImport() {
go func() {
// TODO Move all to DI
i := &Importer{mediaFolder: beego.AppConfig.String("musicFolder")}
- utils.ResolveDependency(&i.mfRepo)
- utils.ResolveDependency(&i.albumRepo)
- utils.ResolveDependency(&i.artistRepo)
- utils.ResolveDependency(&i.idxRepo)
- utils.ResolveDependency(&i.plsRepo)
- utils.ResolveDependency(&i.propertyRepo)
- utils.ResolveDependency(&i.search)
- utils.ResolveDependency(&i.scanner)
+ utils.ResolveDependencies(&i.mfRepo, &i.albumRepo, &i.artistRepo, &i.idxRepo, &i.plsRepo,
+ &i.propertyRepo, &i.search, &i.scanner)
i.Run()
}()
}
diff --git a/utils/graph.go b/utils/graph.go
index 881e40288..b1ec09778 100644
--- a/utils/graph.go
+++ b/utils/graph.go
@@ -25,8 +25,10 @@ func DefineSingleton(ptr interface{}, constructor interface{}) interface{} {
return ptr
}
-func ResolveDependency(ptr interface{}) {
- inject.ExtractAssignable(Graph, ptr)
+func ResolveDependencies(ptrs ...interface{}) {
+ for _, p := range ptrs {
+ inject.ExtractAssignable(Graph, p)
+ }
}
func init() {