di

package
v1.0.78 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

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

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 MakeProvider0[R any](
	token InjectionToken[R],
	fct func() IOE.IOEither[error, R],
) DIE.Provider

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 MakeProvider3 added in v1.0.69

func MakeProvider3[T1, T2, T3, R any](
	token InjectionToken[R],
	d1 Dependency[T1],
	d2 Dependency[T2],
	d3 Dependency[T3],
	fct func(T1, T2, T3) IOE.IOEither[error, R],
) DIE.Provider

func MakeProvider4 added in v1.0.69

func MakeProvider4[T1, T2, T3, T4, R any](
	token InjectionToken[R],
	d1 Dependency[T1],
	d2 Dependency[T2],
	d3 Dependency[T3],
	d4 Dependency[T4],
	fct func(T1, T2, T3, T4) IOE.IOEither[error, R],
) DIE.Provider

func MakeProviderFactory0

func MakeProviderFactory0[R any](
	fct func() IOE.IOEither[error, R],
) DIE.ProviderFactory

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 MakeProviderFactory3 added in v1.0.69

func MakeProviderFactory3[T1, T2, T3, R any](
	d1 Dependency[T1],
	d2 Dependency[T2],
	d3 Dependency[T3],
	fct func(T1, T2, T3) IOE.IOEither[error, R],
) DIE.ProviderFactory

func MakeProviderFactory4 added in v1.0.69

func MakeProviderFactory4[T1, T2, T3, T4, R any](
	d1 Dependency[T1],
	d2 Dependency[T2],
	d3 Dependency[T3],
	d4 Dependency[T4],
	fct func(T1, T2, T3, T4) IOE.IOEither[error, R],
) DIE.ProviderFactory

func Resolve

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

func MakeTokenWithDefault0[R any](name string, fct func() IOE.IOEither[error, R]) InjectionToken[R]

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

func MakeTokenWithDefault3 added in v1.0.69

func MakeTokenWithDefault3[T1, T2, T3, R any](name string,
	d1 Dependency[T1],
	d2 Dependency[T2],
	d3 Dependency[T3],
	fct func(T1, T2, T3) IOE.IOEither[error, R]) InjectionToken[R]

MakeTokenWithDefault3 create a unique `InjectionToken` for a specific type with an attached default provider

func MakeTokenWithDefault4 added in v1.0.69

func MakeTokenWithDefault4[T1, T2, T3, T4, R any](name string,
	d1 Dependency[T1],
	d2 Dependency[T2],
	d3 Dependency[T3],
	d4 Dependency[T4],
	fct func(T1, T2, T3, T4) IOE.IOEither[error, R]) InjectionToken[R]

MakeTokenWithDefault4 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL