Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Automated dump
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jan 9, 2024
1 parent c2e9528 commit 83648ae
Show file tree
Hide file tree
Showing 9 changed files with 1,527 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@

[Raspberry Pi](Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Raspberry%20Pi%208338818b995d4ff78ae4e2594453ee91.md)

[TUI](Development%2002aeaf9ec9954f86bd08ea3bd620f04a/TUI%20d8daef29aa6b4908aed525f2e1243a6c.md)
[TUI](Development%2002aeaf9ec9954f86bd08ea3bd620f04a/TUI%20d8daef29aa6b4908aed525f2e1243a6c.md)

[Patterns](Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Patterns%20c9fbf0af8e1648ee80d4ddedd63983f1.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Patterns

[Dependency Injection](Patterns%20c9fbf0af8e1648ee80d4ddedd63983f1/Dependency%20Injection%207193bc478cee4995b7538edcfbcc189e.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Dependency Injection

# Types

There are three types of Dependency Injection:

- Type 1 IoC (Constructor Injection)
- Type 2 IoC (Setter Injection)
- Type 3 IoC (Interface Injection)

## Constructor Injection

[As Martin Fowler describes constructor injection](https://martinfowler.com/articles/injection.html), there is mostly a sort of assembler or container system involved where you can register implementations used for specific interfaces and where dependencies and dependents are defined.

Then, the actual dependency is passed into a constructor of a class using an interface defining the dependencies behavior.

![[Source: Martin Fowler](https://martinfowler.com/articles/injection/injector.gif)](Dependency%20Injection%207193bc478cee4995b7538edcfbcc189e/Untitled.png)

[Source: Martin Fowler](https://martinfowler.com/articles/injection/injector.gif)

```
class MovieLister...
public MovieLister(MovieFinder finder) {
this.finder = finder;
}
class ColonMovieFinder...
public ColonMovieFinder(String filename) {
this.filename = filename;
}
private MutablePicoContainer configureContainer() {
MutablePicoContainer pico = new DefaultPicoContainer();
Parameter[] finderParams = {new ConstantParameter("movies1.txt")};
pico.registerComponentImplementation(MovieFinder.class, ColonMovieFinder.class, finderParams);
pico.registerComponentImplementation(MovieLister.class);
return pico;
}
```

## Setter Injection

```go
type MovieFinder struct {
lister MovieLister
}

func (t *MovieFinder) SetLister(lister MovieLister) {
t.lister = lister
}
```

## Interface Injection

Almost the same as setter injection, but the injector method is specified by an interface.

```go
public interface ServiceSetter {
void setService(Service service);
}

public class Client implements ServiceSetter {
private Service service;

@Override
public void setService(Service service) {
if (service == null) {
throw new IllegalArgumentException("service must not be null");
}
this.service = service;
}
}

public class ServiceInjector {
private final Set<ServiceSetter> clients = new HashSet<>();

public void inject(ServiceSetter client) {
this.clients.add(client);
client.setService(new ExampleService());
}

public void switch() {
for (Client client : this.clients) {
client.setService(new AnotherExampleService());
}
}
}

public class ExampleService implements Service {}

public class AnotherExampleService implements Service {}
```

# Resources

## Articles

- [https://martinfowler.com/articles/injection.html](https://martinfowler.com/articles/injection.html)
- [https://en.wikipedia.org/wiki/Dependency_injection](https://en.wikipedia.org/wiki/Dependency_injection)

## Videos

- [https://youtu.be/J1f5b4vcxCQ](https://youtu.be/J1f5b4vcxCQ)
- [https://youtu.be/yunF2PgJlHU](https://youtu.be/yunF2PgJlHU)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -673,4 +673,4 @@
background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%2216%22%20height%3D%2216%22%20viewBox%3D%220%200%2016%2016%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%0A%3Crect%20x%3D%220.75%22%20y%3D%220.75%22%20width%3D%2214.5%22%20height%3D%2214.5%22%20fill%3D%22white%22%20stroke%3D%22%2336352F%22%20stroke-width%3D%221.5%22%2F%3E%0A%3C%2Fsvg%3E");
}

</style></head><body><article id="02aeaf9e-c995-4f86-bd08-ea3bd620f04a" class="page sans"><header><h1 class="page-title">Development</h1><p class="page-description"></p></header><div class="page-body"><figure id="57ea550e-e03c-4231-a496-757528e38b73" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/DevOps%2057ea550ee03c4231a496757528e38b73.html">DevOps</a></figure><figure id="804cd266-6dec-4445-9d51-f8892be5412e" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Web%20Development%20804cd2666dec44459d51f8892be5412e.html">Web Development</a></figure><figure id="f264e815-b0b4-4efc-9c8a-8e4bd5e90850" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Languages%20f264e815b0b44efc9c8a8e4bd5e90850.html">Languages</a></figure><figure id="cb330929-7ee2-44a2-a914-a3e358ef4a33" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Linux%20cb3309297ee244a2a914a3e358ef4a33.html">Linux</a></figure><figure id="44ac85c1-e084-44a0-950a-73badbd30851" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Authentication%2044ac85c1e08444a0950a73badbd30851.html">Authentication</a></figure><figure id="2445a249-473f-4e7e-9322-137508116ff8" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Tools%202445a249473f4e7e9322137508116ff8.html">Tools</a></figure><figure id="adaf0558-9db2-404e-9f24-cabb31fd42c8" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Vim%20adaf05589db2404e9f24cabb31fd42c8.html">Vim</a></figure><figure id="74efe2b9-d9ba-405c-959f-84154ed6efd0" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Git%2074efe2b9d9ba405c959f84154ed6efd0.html">Git</a></figure><figure id="8338818b-995d-4ff7-8ae4-e2594453ee91" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Raspberry%20Pi%208338818b995d4ff78ae4e2594453ee91.html">Raspberry Pi</a></figure><figure id="d8daef29-aa6b-4908-aed5-25f2e1243a6c" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/TUI%20d8daef29aa6b4908aed525f2e1243a6c.html">TUI</a></figure></div></article><span class="sans" style="font-size:14px;padding-top:2em"></span></body></html>
</style></head><body><article id="02aeaf9e-c995-4f86-bd08-ea3bd620f04a" class="page sans"><header><h1 class="page-title">Development</h1><p class="page-description"></p></header><div class="page-body"><figure id="57ea550e-e03c-4231-a496-757528e38b73" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/DevOps%2057ea550ee03c4231a496757528e38b73.html">DevOps</a></figure><figure id="804cd266-6dec-4445-9d51-f8892be5412e" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Web%20Development%20804cd2666dec44459d51f8892be5412e.html">Web Development</a></figure><figure id="f264e815-b0b4-4efc-9c8a-8e4bd5e90850" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Languages%20f264e815b0b44efc9c8a8e4bd5e90850.html">Languages</a></figure><figure id="cb330929-7ee2-44a2-a914-a3e358ef4a33" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Linux%20cb3309297ee244a2a914a3e358ef4a33.html">Linux</a></figure><figure id="44ac85c1-e084-44a0-950a-73badbd30851" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Authentication%2044ac85c1e08444a0950a73badbd30851.html">Authentication</a></figure><figure id="2445a249-473f-4e7e-9322-137508116ff8" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Tools%202445a249473f4e7e9322137508116ff8.html">Tools</a></figure><figure id="adaf0558-9db2-404e-9f24-cabb31fd42c8" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Vim%20adaf05589db2404e9f24cabb31fd42c8.html">Vim</a></figure><figure id="74efe2b9-d9ba-405c-959f-84154ed6efd0" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Git%2074efe2b9d9ba405c959f84154ed6efd0.html">Git</a></figure><figure id="8338818b-995d-4ff7-8ae4-e2594453ee91" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Raspberry%20Pi%208338818b995d4ff78ae4e2594453ee91.html">Raspberry Pi</a></figure><figure id="d8daef29-aa6b-4908-aed5-25f2e1243a6c" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/TUI%20d8daef29aa6b4908aed525f2e1243a6c.html">TUI</a></figure><figure id="c9fbf0af-8e16-48ee-80d4-ddedd63983f1" class="link-to-page"><a href="Development%2002aeaf9ec9954f86bd08ea3bd620f04a/Patterns%20c9fbf0af8e1648ee80d4ddedd63983f1.html">Patterns</a></figure></div></article><span class="sans" style="font-size:14px;padding-top:2em"></span></body></html>
Loading

0 comments on commit 83648ae

Please sign in to comment.