Closed
Description
Proposal
Instead of using globals for the server, the config, the database connection, etc, we could use structures. That way, every component that is currently more or less a "singleton" could have multiple properly separated instances.
Using config as an example, the config.Load()
function would return a *config.Config
, a structure that would implement Get()
, Set()
, etc.
This would require changes to fundamentals of the framework, such as the Handlers. Instead of receiving *goyave.Request
and *goyave.Response
, they would receive *goyave.Context
, containing the request, the response, but also the config, a DB connection, etc.
Benefits
- Easier and parallel testing.
- More flexible API thanks to using a context for handlers.
- Multiple servers could run within the same app (not recommended though. Goyave was originally made thinking you would/should only run one REST service from your app).
- Less mutex locks because some global values such as the database connection would be passed by the context.
- Cleaner overall than using globals everywhere.
Drawbacks
- This would be a huge breaking change and would require a lot of work to upgrade from v3.
- Some more code would be required in all components. From
config.Get()
toctx.Config.Get()
for example. - Some features would be less accessible from outside handlers, middleware, etc.
- Will probably require a bit more code in the main function (need to specify config for example).
Questions
- Should the language package be rewritten using the same logic? This wouldn't have many benefits compared to the rest.
- Are all these changes worth it? The main concrete advantage would be parallel testing, but at the cost of some ease of writing the application code.
- Feel free to discuss and express your opinion.
Metadata
Metadata
Assignees
Labels
No labels