Skip to content

E0420: A removed way to declare a dependency ​

A dependency is written one way: a struct with a constructor whose parameters are its own dependencies, registered in main with app.Service(NewX). Hooks and handlers take it as a parameter, by type, as they take the context, the form and the request. @web.Service on a type and the inject: struct tag are gone; the compiler reports them, and vukavet reports an inject: tag in Go.

The constructor Vuka writes for a decorated struct (a controller, a live page) takes its pointer and interface fields, and nothing else: a mutex, a map or a counter is the struct's own, with no tag to say so. A struct needing anything else writes its own New.

Wrong ​

vuka
@web.Service
type Notes struct {
	db   *DB
	mu   sync.Mutex `inject:"-"`
	list []Note     `inject:"-"`
}
vuka
type Notes struct {
	db   *DB
	mu   sync.Mutex
	list []Note
}

func NewNotes(db *DB) *Notes { return &Notes{db: db} }

func main() {
	app := web.New()
	app.Service(NewNotes)
	app.Run("")
}

Released under the MIT License. Vuka builds on Go and its tools, which are made by the Go Authors. Vuka is not affiliated with Google or the Go project. Go is a trademark of Google LLC.