Skip to content

Commit

Permalink
Merge branch 'master' of github.com:golobby/container
Browse files Browse the repository at this point in the history
  • Loading branch information
miladrahimi committed Aug 23, 2021
2 parents d38e89d + 82eac3e commit 8ccc92d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![CI](https://github.com/golobby/container/actions/workflows/ci.yml/badge.svg)](https://github.com/golobby/container/actions/workflows/ci.yml)
[![CodeQL](https://github.com/golobby/container/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/golobby/container/actions/workflows/codeql-analysis.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/golobby/container)](https://goreportcard.com/report/github.com/golobby/container)
[![Coverage Status](https://coveralls.io/repos/github/golobby/container/badge.svg?branch=master)](https://coveralls.io/github/golobby/container?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/golobby/container/badge.svg?v=3)](https://coveralls.io/github/golobby/container?branch=master)
[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)

# Container
Expand Down
15 changes: 3 additions & 12 deletions pkg/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ func (c Container) arguments(function interface{}) ([]reflect.Value, error) {
abstraction := reflectedFunction.In(i)

if concrete, exist := c[abstraction][""]; exist {
instance, err := concrete.resolve(c)
if err != nil {
return nil, err
}
instance, _ := concrete.resolve(c)

arguments[i] = reflect.ValueOf(instance)
} else {
Expand Down Expand Up @@ -159,10 +156,7 @@ func (c Container) NamedResolve(abstraction interface{}, name string) error {
elem := receiverType.Elem()

if concrete, exist := c[elem][name]; exist {
instance, err := concrete.resolve(c)
if err != nil {
return err
}
instance, _ := concrete.resolve(c)

reflect.ValueOf(abstraction).Elem().Set(reflect.ValueOf(instance))

Expand Down Expand Up @@ -204,10 +198,7 @@ func (c Container) Fill(structure interface{}) error {
}

if concrete, exist := c[f.Type()][name]; exist {
instance, err := concrete.resolve(c)
if err != nil {
return err
}
instance, _ := concrete.resolve(c)

ptr := reflect.NewAt(f.Type(), unsafe.Pointer(f.UnsafeAddr())).Elem()
ptr.Set(reflect.ValueOf(instance))
Expand Down
9 changes: 9 additions & 0 deletions pkg/container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ func TestContainer_Singleton_With_Resolvable_Arguments(t *testing.T) {
assert.NoError(t, err)
}

func TestContainer_Singleton_With_Non_Resolvable_Arguments(t *testing.T) {
instance.Reset()

err := instance.Singleton(func(s Shape) Shape {
return &Circle{a: s.GetArea()}
})
assert.EqualError(t, err, "container: no concrete found for: container_test.Shape")
}

func TestContainer_NamedSingleton(t *testing.T) {
err := instance.NamedSingleton("theCircle", func() Shape {
return &Circle{a: 13}
Expand Down

0 comments on commit 8ccc92d

Please sign in to comment.