Documentation
¶
Overview ¶
Copyright (c) 2023 IBM Corp. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2023 IBM Corp. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- func ConstProvider[R any](token InjectionToken[R], value R) DIE.Provider
- func MakeProvider0[R any](token InjectionToken[R], fct func() IOE.IOEither[error, R]) DIE.Provider
- func MakeProvider1[T1, R any](token InjectionToken[R], d1 Dependency[T1], ...) DIE.Provider
- func MakeProvider2[T1, T2, R any](token InjectionToken[R], d1 Dependency[T1], d2 Dependency[T2], ...) DIE.Provider
- func MakeProviderFactory0[R any](fct func() IOE.IOEither[error, R]) DIE.ProviderFactory
- func MakeProviderFactory1[T1, R any](d1 Dependency[T1], fct func(T1) IOE.IOEither[error, R]) DIE.ProviderFactory
- func MakeProviderFactory2[T1, T2, R any](d1 Dependency[T1], d2 Dependency[T2], fct func(T1, T2) IOE.IOEither[error, R]) DIE.ProviderFactory
- func Resolve[T any](token InjectionToken[T]) RIOE.ReaderIOEither[DIE.InjectableFactory, error, T]
- type Dependency
- type InjectionToken
- func MakeToken[T any](name string) InjectionToken[T]
- func MakeTokenWithDefault[T any](name string, providerFactory DIE.ProviderFactory) InjectionToken[T]
- func MakeTokenWithDefault0[R any](name string, fct func() IOE.IOEither[error, R]) InjectionToken[R]
- func MakeTokenWithDefault1[T1, R any](name string, d1 Dependency[T1], fct func(T1) IOE.IOEither[error, R]) InjectionToken[R]
- func MakeTokenWithDefault2[T1, T2, R any](name string, d1 Dependency[T1], d2 Dependency[T2], ...) InjectionToken[R]
- type MultiInjectionToken
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConstProvider ¶
func ConstProvider[R any](token InjectionToken[R], value R) DIE.Provider
ConstProvider simple implementation for a provider with a constant value
func MakeProvider0 ¶
func MakeProvider1 ¶
func MakeProvider1[T1, R any]( token InjectionToken[R], d1 Dependency[T1], fct func(T1) IOE.IOEither[error, R], ) DIE.Provider
func MakeProvider2 ¶
func MakeProvider2[T1, T2, R any]( token InjectionToken[R], d1 Dependency[T1], d2 Dependency[T2], fct func(T1, T2) IOE.IOEither[error, R], ) DIE.Provider
func MakeProviderFactory0 ¶
func MakeProviderFactory1 ¶
func MakeProviderFactory1[T1, R any]( d1 Dependency[T1], fct func(T1) IOE.IOEither[error, R], ) DIE.ProviderFactory
func MakeProviderFactory2 ¶
func MakeProviderFactory2[T1, T2, R any]( d1 Dependency[T1], d2 Dependency[T2], fct func(T1, T2) IOE.IOEither[error, R], ) DIE.ProviderFactory
func Resolve ¶
func Resolve[T any](token InjectionToken[T]) RIOE.ReaderIOEither[DIE.InjectableFactory, error, T]
Resolve performs a type safe resolution of a dependency
Types ¶
type Dependency ¶
type Dependency[T any] interface { DIE.Dependency // Unerase converts a value with erased type signature into a strongly typed value Unerase(val any) E.Either[error, T] }
Dependency describes the relationship to a service, that has a type and a behaviour such as required, option or lazy
type InjectionToken ¶
type InjectionToken[T any] interface { Dependency[T] // Identity idenifies this dependency as a mandatory, required dependency, it will be resolved eagerly and injected as `T`. // If the dependency cannot be resolved, the resolution process fails Identity() Dependency[T] // Option identifies this dependency as optional, it will be resolved eagerly and injected as `O.Option[T]`. // If the dependency cannot be resolved, the resolution process continues and the dependency is represented as `O.None[T]` Option() Dependency[O.Option[T]] // IOEither identifies this dependency as mandatory but it will be resolved lazily as a `IOE.IOEither[error, T]`. This // value is memoized to make sure the dependency is a singleton. // If the dependency cannot be resolved, the resolution process fails IOEither() Dependency[IOE.IOEither[error, T]] // IOOption identifies this dependency as optional but it will be resolved lazily as a `IOO.IOOption[T]`. This // value is memoized to make sure the dependency is a singleton. // If the dependency cannot be resolved, the resolution process continues and the dependency is represented as the none value. IOOption() Dependency[IOO.IOOption[T]] }
InjectionToken uniquely identifies a dependency by giving it an Id, Type and name
func MakeToken ¶
func MakeToken[T any](name string) InjectionToken[T]
MakeToken create a unique `InjectionToken` for a specific type
func MakeTokenWithDefault ¶
func MakeTokenWithDefault[T any](name string, providerFactory DIE.ProviderFactory) InjectionToken[T]
MakeToken create a unique `InjectionToken` for a specific type
func MakeTokenWithDefault0 ¶
MakeTokenWithDefault0 create a unique `InjectionToken` for a specific type with an attached default provider
func MakeTokenWithDefault1 ¶
func MakeTokenWithDefault1[T1, R any](name string, d1 Dependency[T1], fct func(T1) IOE.IOEither[error, R]) InjectionToken[R]
MakeTokenWithDefault1 create a unique `InjectionToken` for a specific type with an attached default provider
func MakeTokenWithDefault2 ¶
func MakeTokenWithDefault2[T1, T2, R any](name string, d1 Dependency[T1], d2 Dependency[T2], fct func(T1, T2) IOE.IOEither[error, R]) InjectionToken[R]
MakeTokenWithDefault2 create a unique `InjectionToken` for a specific type with an attached default provider
type MultiInjectionToken ¶
type MultiInjectionToken[T any] interface { // Container returns the injection token used to request an array of all provided items Container() InjectionToken[[]T] // Item returns the injection token used to provide an item Item() InjectionToken[T] }
MultiInjectionToken uniquely identifies a dependency by giving it an Id, Type and name.
func MakeMultiToken ¶
func MakeMultiToken[T any](name string) MultiInjectionToken[T]
MakeMultiToken creates a MultiInjectionToken