4 ms·
But you still need to send around the object that implements the interface, right? That’s “DI”.
by ptr 6y ago
But you still need to send around the object that implements the interface, right? That’s “DI”.
- jamra 6y agoI don't think you need to do that. Assuming a web application... You can instantiate the object in your main func and then attach it to the server struct so that it is available in every request. When mocking, you can create a mock server that instantiates mock items that implement the interface. If you need something that is contextual, you attach it to the context. In that case, you can still use mock objects, however, you would have to use a different middleware that handles the mock context objects instead of the normal middleware.