Skip to content

Commit

Permalink
sep. keyed&unkeyed getters
Browse files Browse the repository at this point in the history
  • Loading branch information
Firas Darwish committed Nov 15, 2024
1 parent 408a56f commit 393b845
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 19 deletions.
15 changes: 15 additions & 0 deletions container_keyed_getters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ore

import (
"context"
)

// GetFromContainer Retrieves an instance from the given container based on type and key (panics if no valid implementations)
func GetKeyedFromContainer[T any](con *Container, ctx context.Context, key ...KeyStringer) (T, context.Context) {
return getFromContainer[T](con, ctx, key...)
}

// GetListFromContainer Retrieves a list of instances from the given container based on type and key
func GetKeyedListFromContainer[T any](con *Container, ctx context.Context, key ...KeyStringer) ([]T, context.Context) {
return getListFromContainer[T](con, ctx, key...)
}
9 changes: 5 additions & 4 deletions container_getters.go → container_unkeyed_getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import (
)

// GetFromContainer Retrieves an instance from the given container based on type and key (panics if no valid implementations)
func GetFromContainer[T any](con *Container, ctx context.Context, key ...KeyStringer) (T, context.Context) {
return getFromContainer[T](con, ctx, key...)
func GetFromContainer[T any](con *Container, ctx context.Context) (T, context.Context) {
return getFromContainer[T](con, ctx)
}

// GetListFromContainer Retrieves a list of instances from the given container based on type and key
func GetListFromContainer[T any](con *Container, ctx context.Context, key ...KeyStringer) ([]T, context.Context) {
return getListFromContainer[T](con, ctx, key...)
func GetListFromContainer[T any](con *Container, ctx context.Context) ([]T, context.Context) {
return getListFromContainer[T](con, ctx)
}

// TODO sep. to a file
// GetResolvedSingletonsFromContainer retrieves a list of Singleton instances that implement the [TInterface] from the given container.
// See [GetResolvedSingletons] for more information.
func GetResolvedSingletonsFromContainer[TInterface any](con *Container) []TInterface {
Expand Down
15 changes: 0 additions & 15 deletions default_container_getters.go

This file was deleted.

15 changes: 15 additions & 0 deletions default_container_keyed_getters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ore

import (
"context"
)

// GetKeyed Retrieves an instance based on type and key (panics if no valid implementations)
func GetKeyed[T any](ctx context.Context, key ...KeyStringer) (T, context.Context) {
return getFromContainer[T](DefaultContainer, ctx, key...)
}

// GetKeyedList Retrieves a list of instances based on type and key
func GetKeyedList[T any](ctx context.Context, key ...KeyStringer) ([]T, context.Context) {
return getListFromContainer[T](DefaultContainer, ctx, key...)
}
15 changes: 15 additions & 0 deletions default_container_unkeyed_getters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ore

import (
"context"
)

// Get Retrieves an instance based on type and key (panics if no valid implementations)
func Get[T any](ctx context.Context) (T, context.Context) {
return getFromContainer[T](DefaultContainer, ctx)
}

// GetList Retrieves a list of instances based on type and key
func GetList[T any](ctx context.Context) ([]T, context.Context) {
return getListFromContainer[T](DefaultContainer, ctx)
}

0 comments on commit 393b845

Please sign in to comment.