I've been bending over to manage multi tenancy with Neo4j. First of all many thanks for 4.0.0 feature of having more than 1 DB per server. Second I've seen that you will support some form of switching database.
My problem is that I need server to switch database on each HTTP request. That is if user sends header X-TENANT-ID for example, some filter should detect it and set that to the driver for that particular scope of request. This should also be possible with subdomain etc.
I would love it if it was possible to somehow intercept the Neo4j template or Neo4j client or whichever is the correct one to be manipulated before queries get executed.
Most approaches use Singletons for repositories which in this case could be problematic as I need repositories to be able to execute queries against more than 1 database at the same time. I made special class for manipulating tenant and I'm testing it against the Mongo but I have no idea how to inject it to Neo4j nor is it possible at all if using SDN/RX and wanting all those mappers to work.
As an example:
2 users send HTTP requests at the same time and they execute concurrently.
User A sends X-TENANT-ID as Client1
User B sends X-TENANT-ID as Client2
Repositories call getSession() which resolves DatabaseName from the special service
For user A getSession() returns connection to Database1
For user B getSession() returns connection to Database2
Queries get executed against correct DB and results are returned