Created
May 19, 2018 11:00
-
-
Save thanhhh/669e671c383337c891ab309f531b35d4 to your computer and use it in GitHub Desktop.
Check dependency injection instances between parent and child
This file contains hidden or 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
// https://play.golang.org/p/FNyxFKcizua | |
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
s := "Hello" | |
b := Base{Logger: &s} | |
fmt.Printf("Base's Logger: %p\n",b) | |
r := NewRepository(b) | |
fmt.Printf("Repository: %p\n", r) | |
fmt.Printf("Repository's Logger: %p\n", r.Logger) | |
r2 := NewRepository(b) | |
fmt.Printf("Repository2: %p\n", r2) | |
fmt.Printf("Repository2's Logger: %p\n", r2.Logger) | |
} | |
type Base struct { | |
Logger *string | |
} | |
type Repository struct { | |
Base | |
Value int | |
} | |
func NewRepository(b Base) *Repository { | |
return &Repository{ | |
Base: b, | |
} | |
} | |
// Base's Logger: %!p(main.Base={0x1040c128}) | |
// Repository: 0x1040c138 | |
// Repository's Logger: 0x1040c128 | |
// Repository2: 0x1040c140 | |
// Repository2's Logger: 0x1040c128 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment