-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/support non interface types (#10)
Adds support for non-interface types (both registration and resolving) * Allows reflect.Pointer type for registration and activation * Refactors service_type.go module (adds struct with name and reflected type to replace all usages of refect.Type) * Adds new tests
- Loading branch information
1 parent
3be652b
commit 5899c46
Showing
16 changed files
with
185 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package tests | ||
|
||
import ( | ||
"context" | ||
"github.com/matzefriedrich/parsley/pkg/registration" | ||
"github.com/matzefriedrich/parsley/pkg/resolving" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func Test_Registry_RegisterInstance_accepts_pointer(t *testing.T) { | ||
|
||
// Arrange | ||
registry := registration.NewServiceRegistry() | ||
|
||
options := NewOptions("value") | ||
|
||
// Act | ||
err := registration.RegisterInstance(registry, options) | ||
resolver := resolving.NewResolver(registry) | ||
actual, _ := resolving.ResolveRequiredService[*someOptions](resolver, resolving.NewScopedContext(context.Background())) | ||
|
||
// Assert | ||
assert.NoError(t, err) | ||
assert.NotNil(t, actual) | ||
assert.Equal(t, options.value, actual.value) | ||
} | ||
|
||
func Test_Registry_RegisterInstance_resolve_object_with_pointer_dependency(t *testing.T) { | ||
|
||
// Arrange | ||
registry := registration.NewServiceRegistry() | ||
|
||
options := NewOptions("value") | ||
_ = registration.RegisterInstance(registry, options) | ||
_ = registration.RegisterTransient(registry, NewOptionsConsumer) | ||
|
||
resolver := resolving.NewResolver(registry) | ||
|
||
// Act | ||
actual, _ := resolving.ResolveRequiredService[*optionsConsumer](resolver, resolving.NewScopedContext(context.Background())) | ||
|
||
// Assert | ||
assert.NotNil(t, actual) | ||
} | ||
|
||
type someOptions struct { | ||
value string | ||
} | ||
|
||
func NewOptions(value string) *someOptions { | ||
return &someOptions{value} | ||
} | ||
|
||
type optionsConsumer struct { | ||
options *someOptions | ||
} | ||
|
||
func NewOptionsConsumer(options *someOptions) *optionsConsumer { | ||
return &optionsConsumer{ | ||
options: options, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.