Adding function to API

I’d like to add a function to the general Omeka API so it can be accessed on any page that the API can be accessed from. I’ve tried many different methods of doing so and all seem to lead back to a Zend\ServiceManager\Exception\ServiceNotFoundException (even though I do have factories defined in module.config.php. My current code can be found at
Any help is greatly appreciated!