Documentation › Traditional web application › Injecting dependencies
The application struct, defined in the cmd/web/main.go file, holds the dependencies for your handlers, middleware, and helper functions.
Because handlers, middleware, and helpers are defined as methods on the application struct, they have access to its fields.
The exact contents of the application struct will depend on the options you select when generating your codebase. In most cases, however, it will contain at least a copy of the configuration values in the config field, the database model in the db field, and the logger in the logger field, like so:
type application struct {
config config
db *database.DB
logger *slog.Logger
wg sync.WaitGroup
}
Feel free to add new fields to the application struct for any additional dependencies that your handlers, middleware, or helper functions need. These dependencies should be initialized in the run() function in cmd/web/main.go and added to the application struct in the same way as the existing dependencies.