-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
635 additions
and
954 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Scope tree | ||
description: Visualize your module tree | ||
sidebar_position: 1 | ||
--- |
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,5 @@ | ||
--- | ||
title: Service dependencies | ||
description: Understand your dependency graph | ||
sidebar_position: 2 | ||
--- |
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,67 @@ | ||
--- | ||
title: Service registry | ||
description: Learn how to troubleshoot service registry | ||
sidebar_position: 3 | ||
--- | ||
|
||
# Service registry | ||
|
||
## Service name | ||
|
||
Each service is identified in the DI container by a slug. | ||
|
||
When using implicit naming, the `do` framework infers the service name from the type, by using the [go-type-to-string](https://github.com/samber/go-type-to-string) library. | ||
|
||
For debugging purposes, you might want to print the service name. | ||
|
||
```go | ||
i := do.New() | ||
|
||
do.Provide(i, func(i do.Injector) (*MyService, error) { | ||
return &MyService{}, nil | ||
}) | ||
|
||
println(do.Name[*MyService](i)) | ||
// *github.com/samber/example.MyService | ||
``` | ||
|
||
## Provided services | ||
|
||
For debugging purposes, the list of services provided to the container can be printed: | ||
|
||
```go | ||
i := do.New() | ||
|
||
do.Provide(i, func(i do.Injector) (*MyService, error) { | ||
return &MyService{}, nil | ||
}) | ||
do.ProvideNamed(i, "a-number", 42) | ||
|
||
services := i.ListProvidedServices() | ||
println(services) | ||
// []{ | ||
// {ScopeID: "xxxxx", ScopeName: "[root]", Service: "*github.com/samber/example.MyService"}, | ||
// {ScopeID: "xxxxx", ScopeName: "[root]", Service: "a-number"}, | ||
// } | ||
``` | ||
|
||
## Invoked services | ||
|
||
For debugging purposes, the list of invoked services can be printed: | ||
|
||
```go | ||
i := do.New() | ||
|
||
do.Provide(i, func(i do.Injector) (*MyService, error) { | ||
return &MyService{}, nil | ||
}) | ||
do.ProvideNamed(i, "a-number", 42) | ||
|
||
services := i.ListInvokedServices() | ||
println(services) | ||
// []{ | ||
// {ScopeID: "xxxxx", ScopeName: "[root]", Service: "a-number"}, | ||
// } | ||
``` | ||
|
||
In the example above, the lazy-loaded service `*MyService` has not been invoked. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
id: glossary | ||
title: Glossary | ||
description: Dependency injection glossary | ||
sidebar_position: 6 | ||
--- | ||
|
||
# Glossary | ||
|
||
## Dependency Injection (DI) | ||
|
||
A design pattern used in software development to achieve Inversion of Control (IoC) between classes and their dependencies. It's a technique for achieving loose coupling between objects and their collaborators, or dependencies. | ||
|
||
## Inversion of Control (IoC) | ||
|
||
A design principle where the flow of control is inverted compared to traditional procedural programming. Instead of the application-specific code controlling the execution of reusable code, the reusable code controls the execution. This principle is often implemented using techniques such as Dependency Injection, leading to more modular and easily maintainable code. | ||
|
||
## Injector | ||
|
||
In Dependency Injection (DI), an injector is a component that creates instances of classes and manages their dependencies. It's also known as the DI container or IoC (Inversion of Control) container. | ||
|
||
## DI Container | ||
|
||
A DI Container is another term for the Injector in Dependency Injection. It's responsible for providing instances of classes and their dependencies. | ||
|
||
## Scope | ||
|
||
Kind of module. It contains many declaration singleton and service providers. It has access to the services from ancestors' scopes. | ||
|
||
## Root scope | ||
|
||
Top-level scope. | ||
|
||
## Child scope | ||
|
||
A scope that is nested within another scope. Variables defined in a child scope are only accessible within that scope and any nested scopes. | ||
|
||
## DAG | ||
|
||
Stands for Directed Acyclic Graph. It's a concept in mathematics and computer science. In the context of DI, it often refers to the graph of dependencies between different components or services. | ||
|
||
## Provider | ||
|
||
In DI, a provider is a component or a factory that creates instances of a service or a class. | ||
|
||
## Injection | ||
|
||
The process of providing a service to a scope. The injection can be done in different ways like provider injection or setter injection. | ||
|
||
## Invocation | ||
|
||
The process of executing a procedure or function through a call. | ||
|
||
## Lazy Service | ||
|
||
A service in DI that is not created until it is first requested. | ||
|
||
## Eager Service | ||
|
||
A service in DI that is created as soon as the application starts, not when it's first requested. | ||
|
||
## Transient Service | ||
|
||
A service in DI that is created anew each time it is requested. | ||
|
||
## Service Alias | ||
|
||
An alternative name given to a service in DI. It allows a service to be accessed using a different identifier. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Fork | ||
description: Clone your global DI container | ||
sidebar_position: 2 | ||
--- |
Oops, something went wrong.