Compare commits

..

No commits in common. "main" and "v1.5.0" have entirely different histories.
main ... v1.5.0

3 changed files with 1 additions and 25 deletions

View File

@ -84,20 +84,8 @@ func (c *container) destroy(typ reflect.Type, identifier ...string) {
delete(c.instances, instanceSelector) delete(c.instances, instanceSelector)
} }
func (c *container) destroyAllMatching(match func(string) bool) {
c.mu.Lock()
defer c.mu.Unlock()
for key := range c.instances {
if match(key) {
delete(c.instances, key)
}
}
println("")
}
func (c *container) getSelector(typ reflect.Type, identifier ...string) string { func (c *container) getSelector(typ reflect.Type, identifier ...string) string {
typeName := typ.String() typeName := typ.String()
additionalKey := strings.Join(identifier, "_") additionalKey := strings.Join(identifier, "_")
return fmt.Sprintf("%s_%s", additionalKey, typeName) return fmt.Sprintf("%s_%s", typeName, additionalKey)
} }

View File

@ -35,7 +35,3 @@ func Destroy[T any](identifier ...string) {
typ := reflect.TypeOf((*T)(nil)).Elem() typ := reflect.TypeOf((*T)(nil)).Elem()
getContainer().destroy(typ, identifier...) getContainer().destroy(typ, identifier...)
} }
func DestroyAllMatching(match func(string) bool) {
getContainer().destroyAllMatching(match)
}

View File

@ -2,7 +2,6 @@ package di_test
import ( import (
"fmt" "fmt"
"strings"
"testing" "testing"
di "git.apihub24.de/admin/generic-di" di "git.apihub24.de/admin/generic-di"
@ -212,13 +211,6 @@ func TestOverwriteInjectableInstance(t *testing.T) {
} }
} }
func TestDestroyMatching(t *testing.T) {
_ = di.Inject[greetingService]("abc")
_ = di.Inject[greetingService]("def")
_ = di.Inject[greetingService]("abc_def")
di.DestroyAllMatching(func(key string) bool { return strings.HasPrefix(key, "abc") })
}
func TestDestroy(t *testing.T) { func TestDestroy(t *testing.T) {
_ = di.Inject[textService]("a") _ = di.Inject[textService]("a")
di.Destroy[textService]("a") di.Destroy[textService]("a")