Skip to content

Commit

Permalink
fixed misspellings
Browse files Browse the repository at this point in the history
  • Loading branch information
Firas Darwish committed Nov 15, 2024
1 parent 75280fc commit c492a9f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func (this *Container) Validate() {
//provide default value for all placeholders
for _, resolvers := range this.resolvers {
for _, resolver := range resolvers {
if resolver.isPlaceHolder() {
ctx = resolver.providePlaceHolderDefaultValue(this, ctx)
if resolver.isPlaceholder() {
ctx = resolver.providePlaceholderDefaultValue(this, ctx)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal_getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func getListFromContainer[T any](con *Container, ctx context.Context, key KeyStr

for index := 0; index < len(resolvers); index++ {
resolver := resolvers[index]
if resolver.isPlaceHolder() && !resolver.isScopedValueResolved(ctx) {
if resolver.isPlaceholder() && !resolver.isScopedValueResolved(ctx) {
//the resolver is a placeholder and the placeholder's value has not been provided
//don't panic, just skip (don't add anything to the list)
continue
Expand Down
2 changes: 1 addition & 1 deletion ore.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func addResolver[T any](this *Container, resolver serviceResolverImpl[T], key Ke
defer this.lock.Unlock()

resolverID := len(this.resolvers[typeID])
if resolver.isPlaceHolder() {
if resolver.isPlaceholder() {
if resolverID > 0 {
panic(typeAlreadyRegistered(typeID))
}
Expand Down
10 changes: 5 additions & 5 deletions registrars_placeholder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestPlaceHolder_HappyPath(t *testing.T) {
func TestPlaceholder_HappyPath(t *testing.T) {
clearAll()

//register a placeholder
Expand Down Expand Up @@ -47,7 +47,7 @@ func TestPlaceHolder_HappyPath(t *testing.T) {
assert.Equal(t, 1, len(persons))
}

func TestPlaceHolder_ProvideValueBeforeRegistering(t *testing.T) {
func TestPlaceholder_ProvideValueBeforeRegistering(t *testing.T) {
clearAll()

//provide a value to the placeholder
Expand All @@ -67,7 +67,7 @@ func TestPlaceHolder_ProvideValueBeforeRegistering(t *testing.T) {
}

// can not register a placeholder to override a real resolver
func TestPlaceHolder_OverrideRealResolver(t *testing.T) {
func TestPlaceholder_OverrideRealResolver(t *testing.T) {
clearAll()

//register a real resolver
Expand All @@ -85,7 +85,7 @@ func TestPlaceHolder_OverrideRealResolver(t *testing.T) {
})
}

func TestPlaceHolder_OverridePlaceHolder(t *testing.T) {
func TestPlaceholder_OverridePlaceholder(t *testing.T) {
clearAll()
//register a placeholder
RegisterKeyedPlaceholder[*m.Trader]("module2")
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestPlaceHolder_OverridePlaceHolder(t *testing.T) {
}

// placeholder value of a module is not accessible from other module
func TestPlaceHolder_PerModule(t *testing.T) {
func TestPlaceholder_PerModule(t *testing.T) {
con1 := NewContainer()
RegisterPlaceholderToContainer[*m.Trader](con1)

Expand Down
14 changes: 7 additions & 7 deletions serviceResolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ type serviceResolver interface {
//getInvokedSingleton returns the invoked singleton value, or false if the resolver is not a singleton or has not been invoked
getInvokedSingleton() (con *concrete, isInvokedSingleton bool)

//isPlaceHolder returns true if this resolver is a placeholder.
//isPlaceholder returns true if this resolver is a placeholder.
//A placeholder is a special Scoped resolver that doesn't have Creator or Factory (a.k.a anonymousInitializer) function
isPlaceHolder() bool
isPlaceholder() bool

//providePlaceHolderDefaultValue provides a default value for a placeholder for validation
providePlaceHolderDefaultValue(ctn *Container, ctx context.Context) context.Context
//providePlaceholderDefaultValue provides a default value for a placeholder for validation
providePlaceholderDefaultValue(ctn *Container, ctx context.Context) context.Context

// isScopedValueResolved returns true if this resolver is a scoped resolver and the scoped value has been already resolved.
// in case this resolver is a placeholder, then it returns true if the placeholder value has been provided.
Expand Down Expand Up @@ -93,7 +93,7 @@ func (this serviceResolverImpl[T]) resolveService(ctn *Container, ctx context.Co
}
}

if this.isPlaceHolder() {
if this.isPlaceholder() {
panic(placeholderValueNotProvided(this.resolverMetadata))
}

Expand Down Expand Up @@ -201,11 +201,11 @@ func (this resolverMetadata) String() string {
return fmt.Sprintf("Resolver(%s, type={%s}, key='%s')", this.lifetime, getUnderlyingTypeName(this.id.pointerTypeName), this.id.oreKey)
}

func (this serviceResolverImpl[T]) isPlaceHolder() bool {
func (this serviceResolverImpl[T]) isPlaceholder() bool {
return this.lifetime == Scoped && this.anonymousInitializer == nil && this.creatorInstance == nil
}

func (this serviceResolverImpl[T]) providePlaceHolderDefaultValue(ctn *Container, ctx context.Context) context.Context {
func (this serviceResolverImpl[T]) providePlaceholderDefaultValue(ctn *Container, ctx context.Context) context.Context {
defaultValue := *new(T)
concreteValue := &concrete{
value: defaultValue,
Expand Down
4 changes: 2 additions & 2 deletions validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ func TestValidate_MissingDependency(t *testing.T) {
assert2.PanicsWithError(t, assert2.ErrorStartsWith("implementation not found for type"), Validate)
}

func TestValidate_WithPlaceHolder(t *testing.T) {
func TestValidate_WithPlaceholder(t *testing.T) {
con := NewContainer()
RegisterPlaceholderToContainer[*m.Trader](con)
assert.NotPanics(t, con.Validate)
}

func TestValidate_WithPlaceHolderInterface(t *testing.T) {
func TestValidate_WithPlaceholderInterface(t *testing.T) {
con := NewContainer()
RegisterPlaceholderToContainer[m.IPerson](con)
assert.NotPanics(t, con.Validate)
Expand Down

0 comments on commit c492a9f

Please sign in to comment.