Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created August 29, 2021 06:18
Show Gist options
  • Save percybolmer/da0a52d275e4b9121fb15caccef7af41 to your computer and use it in GitHub Desktop.
Save percybolmer/da0a52d275e4b9121fb15caccef7af41 to your computer and use it in GitHub Desktop.
// WithCustomerRepository applies a given customer repository to the OrderService
func WithCustomerRepository(cr customer.CustomerRepository) OrderConfiguration {
// return a function that matches the OrderConfiguration alias,
// You need to return this so that the parent function can take in all the needed parameters
return func(os *OrderService) error {
os.customers = cr
return nil
}
}
// WithMemoryCustomerRepository applies a memory customer repository to the OrderService
func WithMemoryCustomerRepository() OrderConfiguration {
// Create the memory repo, if we needed parameters, such as connection strings they could be inputted here
cr := memory.New()
return WithCustomerRepository(cr)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment