Skip to content

Commit 8af34dd

Browse files
Minor changes... for some reason, reflect.Type isn't a "Comparable" type anymore, don't understand why.
Removed maps.x/slices.x which caused this error
1 parent 47b731d commit 8af34dd

File tree

4 files changed

+39
-22
lines changed

4 files changed

+39
-22
lines changed

container_main.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package container
33
import (
44
"reflect"
55
"unsafe"
6-
7-
"golang.org/x/exp/maps"
86
)
97

108
// ContainerConfig - Holds configuration values... soon I will add some more, make them work fully
@@ -80,16 +78,26 @@ func (container *ContainerInstance) CreateChildContainer() *ContainerInstance {
8078
// ClearInstances - This will just remove any singleton instances from the container
8179
// When they are next resolved via Make/MakeTo, they will be instantiated again
8280
func (container *ContainerInstance) ClearInstances() {
83-
maps.Clear(container.resolved)
81+
for k := range container.resolved {
82+
delete(container.resolved, k)
83+
}
8484
}
8585

8686
// Reset - Reset will empty all bindings in this container, you will have to register
8787
// any bindings again before you can resolve them.
8888
func (container *ContainerInstance) Reset() {
89-
maps.Clear(container.resolved)
90-
maps.Clear(container.bindings)
91-
maps.Clear(container.concretes)
92-
maps.Clear(container.tagged)
89+
for k := range container.resolved {
90+
delete(container.resolved, k)
91+
}
92+
for k := range container.bindings {
93+
delete(container.bindings, k)
94+
}
95+
for k := range container.concretes {
96+
delete(container.concretes, k)
97+
}
98+
for k := range container.tagged {
99+
delete(container.tagged, k)
100+
}
93101
container.parent = nil
94102
}
95103

container_tagged.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,22 @@ package container
22

33
import (
44
"reflect"
5-
6-
"golang.org/x/exp/slices"
75
)
86

97
// Tag - When we've bound to the container, we can then tag the abstracts with a string
108
// This is useful when we want to obtain a "category" of implementations
119
//
1210
// For example; Imagine we have a few different "statistic gathering" services
1311
//
14-
// // Bind our individual services
15-
// Container.Bind(new(NewUserPostViewsStatService), func () {})
16-
// Container.Bind(new(NewPageViewsStatService), func () {})
17-
//
18-
// // Add the services to the "StatServices" "Category"
19-
// Container.Tag("StatServices", new(NewUserPostViewsStatService), new(NewPageViewsStatService))
12+
// // Bind our individual services
13+
// Container.Bind(new(NewUserPostViewsStatService), func () {})
14+
// Container.Bind(new(NewPageViewsStatService), func () {})
2015
//
21-
// // Now we can obtain them all
22-
// Container.Tagged("StatServices")
16+
// // Add the services to the "StatServices" "Category"
17+
// Container.Tag("StatServices", new(NewUserPostViewsStatService), new(NewPageViewsStatService))
2318
//
19+
// // Now we can obtain them all
20+
// Container.Tagged("StatServices")
2421
func (container *ContainerInstance) Tag(tag string, bindings ...any) bool {
2522
if len(bindings) == 0 {
2623
return false
@@ -50,9 +47,20 @@ func (container *ContainerInstance) Tag(tag string, bindings ...any) bool {
5047

5148
// We have types tagged with this tag already, so we need to merge, but make sure they're unique
5249
for _, taggedType := range taggedTypes {
53-
if !slices.Contains(container.tagged[tag], taggedType) {
50+
// check if container.tagged[tag] contains taggedType in the slice
51+
var found bool = false
52+
for _, r := range container.tagged[tag] {
53+
if r == taggedType {
54+
found = true
55+
break
56+
}
57+
}
58+
if !found {
5459
container.tagged[tag] = append(container.tagged[tag], taggedType)
5560
}
61+
// if !slices.Contains(container.tagged[tag], taggedType) {
62+
// container.tagged[tag] = append(container.tagged[tag], taggedType)
63+
// }
5664
}
5765

5866
return len(container.tagged[tag]) > 0

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ go 1.18
44

55
require golang.org/x/exp v0.0.0-20220218215828-6cf2b201936e
66

7-
require github.com/modern-go/reflect2 v1.0.2
7+
require (
8+
github.com/modern-go/reflect2 v1.0.2
9+
github.com/stretchr/testify v1.7.0
10+
)
811

912
require (
1013
github.com/davecgh/go-spew v1.1.0 // indirect
1114
github.com/pmezard/go-difflib v1.0.0 // indirect
12-
github.com/stretchr/objx v0.1.0 // indirect
13-
github.com/stretchr/testify v1.7.0 // indirect
1415
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
1516
)

go.sum

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
44
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
55
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
66
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7-
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
87
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
98
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
109
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
1110
golang.org/x/exp v0.0.0-20220218215828-6cf2b201936e h1:iWVPgObh6F4UDtjBLK51zsy5UHTPLQwCmsNjCsbKhQ0=
1211
golang.org/x/exp v0.0.0-20220218215828-6cf2b201936e/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
12+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1313
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1414
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
1515
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)