Dependency Injection
Last updated
Was this helpful?
Last updated
Was this helpful?
Copper uses google/wire
to enable dependency injection. Check out the to learn more about dependency injection and Wire.
In a Copper project, each package has a wire.go
file. This file is autogenerated if you use the Copper CLI to create your package directories.
Let's say you have the following struct that requires rockets.Queries
and clogger.Logger
for its methods.
To enable automating wiring up of all dependencies, create a constructor for the Launcher
struct.
Finally, add the constructor to the package's WireModule
defined in the wire.go
file.
That's it! Copper + Wire will automatically pass in the correct dependencies to the NewLauncher
constructor.