Hi,
I am porting a personal project to vibe.D which is rather large. I have many routes, each with individual route functions. I've had the darndest time trying to split the routes and their functions into separate files.
Right now I am using the basic layout of vibelog:
https://github.com/rejectedsoftware/vibelog/blob/master/source/vibelog/vibelog.d
I have the route functions in separate files, and I create a View class which is full of utility functions that take up a lot of space and don't change much. I like this setup.
The issue I'm running into is - referring to vibelog - how can I pass the database connection m_db
to route functions located outside of class VibeLog
?
My current solution is to wrap each set of route functions in classes, and inherit-daisy-chain them down to my View class into class VibeLog : View
, with View
inheriting from UserRoutes
, which inherits from MapRoutes
, etc.. This looks bad.
Another good option might be if I could pass this vibelog
to router.get
, such that I could access vibelog.m_db
.
Perhaps I could initialize m_db
outside of class VibeLog
and import it elsewhere.. but I don't like this, and I feel like this might interfere with fiber/thread safety.
Thanks,