You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Really a question more than an actual issue. I've been scanning through the docs but from what I've seen the information on this matter is quite thin. I apologize if this is the wrong place for questions, in which case, I ask you to please point me in the direction of where you wish me to re-post it 🙏
This library presents itself as beeing "type-safe":
It may replace the uber/dig fantastic package in simple Go projects. samber/do uses Go 1.18+ generics and therefore offers a typesafe API.
I am struggling a bit to understand what is meant by that in this context really, and how type-safety is enforced. It seems to me that types are enforced at runtime, which really doesn't provide much "safety" - but perhaps I'm doing something wrong?
I pulled down the repository and took the examples/simple/example.go for a spin. I tried to comment all of the methods that provide Wheel, and was hoping to get a static type-error in my editor or a compile error as nothing of type Wheel is provided, but it turns out that the code compiles and that "Simple example" is indeed printed to the terminal upon invoking it 🤔
package main
import (
// preceeding code unmodified...funcmain() {
fmt.Printf("Simpleexample\n")
injector:=do.New()
// provide wheels// do.ProvideNamedValue(injector, "wheel-1", &Wheel{}) // do.ProvideNamedValue(injector, "wheel-2", &Wheel{})// do.ProvideNamedValue(injector, "wheel-3", &Wheel{})// do.ProvideNamedValue(injector, "wheel-4", &Wheel{})// ...rest of the code unmodified
}
We're currently using uber-fx for dependency injection, and I am not a big fan of the magic it provides. I am trying to understand if samber/do somehow does away with some of that magic, and how it compares in terms of type-safety.
Grateful for any insight into the above, or any pointers to pieces of documentation on type-safety which I may have missed
The text was updated successfully, but these errors were encountered:
Really a question more than an actual issue. I've been scanning through the docs but from what I've seen the information on this matter is quite thin. I apologize if this is the wrong place for questions, in which case, I ask you to please point me in the direction of where you wish me to re-post it 🙏
This library presents itself as beeing "type-safe":
I pulled down the repository and took the
examples/simple/example.go
for a spin. I tried to comment all of the methods that provideWheel
, and was hoping to get a static type-error in my editor or a compile error as nothing of typeWheel
is provided, but it turns out that the code compiles and that "Simple example" is indeed printed to the terminal upon invoking it 🤔We're currently using
uber-fx
for dependency injection, and I am not a big fan of the magic it provides. I am trying to understand ifsamber/do
somehow does away with some of that magic, and how it compares in terms of type-safety.Grateful for any insight into the above, or any pointers to pieces of documentation on type-safety which I may have missed
The text was updated successfully, but these errors were encountered: