Your first implementation looks correct. context should be passed via functions, It will also make testing easier when your dealing with interfaces. Read more about it here go blog