Skip to content

Commit

Permalink
Insert Commit Message Here
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed Dec 1, 2023
1 parent c7b9110 commit b3306d8
Show file tree
Hide file tree
Showing 30 changed files with 635 additions and 954 deletions.
5 changes: 5 additions & 0 deletions docs/docs/debugging/scope-tree.md
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
---
5 changes: 5 additions & 0 deletions docs/docs/debugging/service-dependencies.md
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
---
67 changes: 67 additions & 0 deletions docs/docs/debugging/service-registry.md
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.
57 changes: 0 additions & 57 deletions docs/docs/debugging/to-do-v2.md

This file was deleted.

68 changes: 68 additions & 0 deletions docs/docs/glossary.md
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.
25 changes: 0 additions & 25 deletions docs/docs/scopes/congratulations.md

This file was deleted.

36 changes: 0 additions & 36 deletions docs/docs/scopes/create-a-blog-post.md

This file was deleted.

59 changes: 0 additions & 59 deletions docs/docs/scopes/create-a-document.md

This file was deleted.

33 changes: 0 additions & 33 deletions docs/docs/scopes/deploy-your-site.md

This file was deleted.

5 changes: 5 additions & 0 deletions docs/docs/scopes/fork.md
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
---
Loading

0 comments on commit b3306d8

Please sign in to comment.