Applying config injection to the model layer

Revisiting our register package, we see that it has references to both config and logging:

// Registerer validates the supplied person, calculates the price in // the requested currency and saves the result.// It will return an error when:// -the person object does not include all the fields// -the currency is invalid// -the exchange rate cannot be loaded// -the data layer throws an error.type Registerer struct {}// get price in the requested currencyfunc (r *Registerer) getPrice(ctx context.Context, currency string) (float64, error) {  converter := &exchange.Converter{}  price, err := converter.Do(ctx, config.App.BasePrice, currency)  if err != nil { logging.L.Warn("failed to convert the price. err: ...

Get Hands-On Dependency Injection in Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.