🪟 Windows TippsModify Windows Support Phone Number with PowerShell(03.09.2026 um 00:00 Uhr)
🔧 AI Nachrichten Podcast: ChatGPT schwatzt Nutzern in Deutschland jetzt Werbung auf(28.08.2026 um 08:46 Uhr)
🪟 Windows TippsMicrosoft bringt Emoji 17.0 auf Windows 11(31.08.2026 um 08:16 Uhr)
🪟 Windows TippsModify Windows Support Phone Number with PowerShell(03.09.2026 um 00:00 Uhr)
🔧 AI Nachrichten Podcast: ChatGPT schwatzt Nutzern in Deutschland jetzt Werbung auf(28.08.2026 um 08:46 Uhr)
🪟 Windows TippsMicrosoft bringt Emoji 17.0 auf Windows 11(31.08.2026 um 08:16 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 2 Min Lesezeit
0

DI in my team

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

Bespoke will use Cake Pattern based DI.

We will split the code in different components, each one with a clearly defined scope.

For each component we will define 3 things




  1. A trait



CODE
trait MyService{
...
}






  1. A binding key



CODE
object MyService{
trait Required {
def myService:MyService
}
}






  1. An implementation



CODE
final class DefaultMyService extends MyService {
...
}





Let's avoid the Impl suffix (as explained here)




  1. A Binding



CODE
object DefaultMyService {
trait Provided extends Required{
final override lazy val myService: MyService = new DefaultMyService()
}
}





Finally, for the application we will have




  1. Modules



Which are the grouping of multiple bindings




CODE
trait MyModule extends DefaultMyService.Provided
with DefaultMyOtherService.Provided
with DefaultMyRepo.Provided
with DefaultMyClient.Provided{
}







  1. Containers




CODE
new MyModule with MyOtherModule with YourModule{}









Binding keys



Binding keys are the key to which a component will be associated.

In our case will be a trait called Required as part of the companion object of the trait we want to bind.

That trait will have one single method (def) without parameter lists, whose return type will be the bound trait, and whose name will be clear and explanatory and not prone to collisions.

It's important that it's a DEF and not a VAL, because order initialization is required when using VAL, which makes it very difficult to get right.




CODE
object A{
// NO EXTRA MIXINS
trait Required{
// NO SELF ANNOTATIONS
def a: A // DEF, NOT VAL, NOT LAZY VAL... DEF!
}
}









Bindings



Bindings are defined by a set of dependencies, and a constructor using such dependencies.

In our case it will be a trait in the companion object of out implementation class.

That trait will extend ONLY the Required trait and will implement the method as lazy val (in case of singletons) or def (in case of non singletons).

For good measure a final modifier is encouraged, and for readability an override modifier.

Dependencies will be declared as self annotations, NOT mixins... SELF ANNOTATIONS.

And self annotations to other Required traits.




CODE

object DefaultA{
trait Provided extends Required{
self: B.Required with C.Required with D.Required =>
override final lazy val a = new DefaultA(b,c,d)
}
}


Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Modify Windows Support Phone Number with PowerShell
1 Quelle
Die Zukunft des Einkaufens: Warum wir ein neues Kapitel aufschlagen (und wie du es mitschreiben kannst)
1 Quelle
ZDE Podcast 251: Wie sieht digitales Instore Marketing 2026 aus, Amit Chatterjee?
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten DI in my team

Thematisch verwandte Begriffe: team · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...