-
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instances #166
Comments
I think it would be wiser to push back this kind of change to at least v5. The release of v4 already contains more than enough breaking changes and is long overdue. |
From the above, I think having handler function signature with only Will there be a way to add external components? and do you think the generics in 1.18 could help on this? Thanks. |
@agbaraka I would love to be able to neatly integrate external components / plugins to this. Do you think of a way we could implement this? |
After doing some research on this, I think a cleaner way to have a consistent way for external and internal components is for all components to use globals (which is the current structure). Can we use |
Hello @agbaraka Can you elaborate? Can you provide a simple example of what you have in mind? |
Ok.. So, let's take Using mutex (current implementation) ...
var (
dbConnection *gorm.DB
mu sync.Mutex
...
)
func GetConnection() *gorm.DB {
mu.Lock()
defer mu.Unlock()
if dbConnection == nil {
dbConnection = newConnection()
}
return dbConnection
}
... Using sync.Once ...
var (
dbConnection *gorm.DB
dbConnOnce sync.Once
...
)
func GetConnection() *gorm.DB {
dbConnOnce.Do(func() {
dbConnection = newConnection()
})
return dbConnection
}
... |
If we do this we sacrifice the ability to |
Implemented in v5. |
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 implementGet()
,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
Drawbacks
config.Get()
toctx.Config.Get()
for example.Questions
The text was updated successfully, but these errors were encountered: