Skip to content

Proper Go application structure with dependency injection for unit testing, mocking, and service replacement. Work-in-Progress Design.

Notifications You must be signed in to change notification settings

xeoncross/godiapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Dependency injection App

Test application design + folder package structure to achieve a clean web application that is testable and without strong uncoupling.

This system contains three "databases" to show how easy it is to swap stores when using DI:

  • /mock (Fake backend, for testing)
  • /mysql
  • /ledis (like redis, but in-process like sqlite)

Questions:

Testing + Mocks

Currently the only test (/mock) in here is pointlessly testing itself. How should this be refactored? Should the tests be placed next to the implementations and only use the /mocks?

Scale

How will this approach work with 20+ domain objects (users,likes,comments,etc...)? At the moment the /mysql implementation of UserService has all the possible database queries defined on itself with no separation. Should UserService become a monolithic StoreService or should we add 20+ more ___Service interfaces?

This same question goes for the http handlers and other possible API's such as GraphQL.

Example: Mattermost (OS Slack Alternative)

Mattermost is an example that defines a base store that wraps all the individual entity store interfaces. Then provides sql and other concrete implementations of these interfaces for actual storage. This includes a mock store.

Design choices and Articles:

About

Proper Go application structure with dependency injection for unit testing, mocking, and service replacement. Work-in-Progress Design.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages