Skip to content

Instantly share code, notes, and snippets.

@digitaldreamer
Last active September 16, 2019 18:02
Show Gist options
  • Save digitaldreamer/c88490108056de15d68ddbfdbb2c5a75 to your computer and use it in GitHub Desktop.
Save digitaldreamer/c88490108056de15d68ddbfdbb2c5a75 to your computer and use it in GitHub Desktop.
New Binder Pattern
// We would make a seaprate {service}/data package. The reason to separate out the data module is to utilize
// private methods to not expose lower-level resources
// We would no longer need the big global Databinder and instead replace it with a smaller Binder for each resource
// The benifit of switching off of the interface is we can then leverage private attributes like the clients
// The Binders can expose sqlx components like tx in private functions
// The binder methods would be raw management of the resources with no side-effects (i.e. creating a guest
// would not create a guest token)
type GuestBinder struct {
Get func() error
Update func() error
Insert func() error
DB *DB
Identity *identity.Client
}
func NewGuestBinder(identity identity.Client) *GuestBinder {}
func NewGuestBinderMock() *GuestBinder {}
type TokenBinder struct {
Get func() error
Update func() error
Insert func() error
UpdateBatch func(tx *sqlx.Tx) error
DB *DB
}
func NewTokenBinder(identity identity.Client) *GuestBinder {}
func NewTokenBinderMock() *GuestBinder {}
// The you would dependency inject the binders into the processor.
// These can act as processors which can coordinate and utilize private methods accross the different binders
// i.e. CreateGuest would create a guest, token, and ledger entry etc...
type GuestProcessor struct {
Create func() error {}
ActivateGuest func() error {}
guest *GuestBinder
token *TokenBinder
identity *identity.Client
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment