November 2018
Intermediate to advanced
346 pages
8h 12m
English
The documentation defines a provider as follows:
For our purposes, we can put it a different way—a provider returns an instance of a dependency.
The simplest form a provider can take is a simple no argument function, as shown in the following code:
// Providerfunc ProvideFetcher() *Fetcher { return &Fetcher{}}// Object being "provided"type Fetcher struct {}func (f *Fetcher) GoFetch() (string, error) {
return "", errors.New("not implemented yet")}
Providers can also indicate that they require dependencies to be injected by having parameters like this:
func ProvideFetcher(cache *Cache) *Fetcher { return &Fetcher{ cache: cache, }}
The dependencies (parameters) of this provider ...
Read now
Unlock full access