Robyn icon indicating copy to clipboard operation
Robyn copied to clipboard

[Feature Request] Allow dependency injection and make the objects accessible in the request object

Open sansyrox opened this issue 2 years ago • 3 comments

Current Behavior

No dependency injection is supported right now.

Desired Behavior

Add support for dependency injection. This will allow things like open database connections, loggers to be added once at the top level and be accessible to every route if required.

Something like this

@app.get("/"):
def fx(request, db): # db is possible right now
   print(db)

HIgh Level Implementation

  • Allow variable params in the callable functions
  • Go to the function executors(rust side) and call the functions with variable params

sansyrox avatar Jun 22 '22 09:06 sansyrox

Hii, I am interested in this, I don't really know where to start when we talk about calling the rust side, any comment on this might help me 😄

Noborita9 avatar Mar 08 '23 00:03 Noborita9

@Noborita9 , thank you for the interest 😄 I will be happy to guide you.

I just want to confirm if @kliwongan is not working on this in their PR(https://github.com/sansyrox/robyn/pull/363) here.

sansyrox avatar Mar 09 '23 22:03 sansyrox

Sorry for the late response; I would want to work on a similar feature, but I believe that once my work is done, it shouldn't be too difficult to extend the additions to allow for proper dependency injection. I'll make sure of that.

EDIT: Just to clarify I will not be working on dependency injection specifically, just the validation stuff; if you want, you can wait until that's done so that it's easier to work on dependency injection? I should be able to finish it soon.

kliwongan avatar Mar 19 '23 00:03 kliwongan