fastapi-react icon indicating copy to clipboard operation
fastapi-react copied to clipboard

Question on middleware implementation

Open NixBiks opened this issue 5 years ago • 3 comments

Hi @Buuntu

I really like your boilerplate here - there's a lot of good practices to study I think. I stumbled upon one thing that puzzles me a bit though. You add middleware to create a database session for each request and close it again. But you also create a dependency to do the same if I'm not mistaken?

I imagine that you first implemented the middleware approach but realized you could solve it with dependency injection instead? I'm curious if I'm wrong in my perception?

NixBiks avatar Oct 06 '20 14:10 NixBiks

Another thing that puzzles me is get_test_db_url() in conftest.py. To me it looks like it points to a dbname that doesn't exist? But maybe that's not a problem with postgres?

NixBiks avatar Oct 06 '20 21:10 NixBiks

Another thing that puzzles me is get_test_db_url() in conftest.py. To me it looks like it points to a dbname that doesn't exist? But maybe that's not a problem with postgres?

This is because it's a test fixture, you don't want it to point to a real database.

Buuntu avatar Oct 08 '20 18:10 Buuntu

Hi @Buuntu

I really like your boilerplate here - there's a lot of good practices to study I think. I stumbled upon one thing that puzzles me a bit though. You add middleware to create a database session for each request and close it again. But you also create a dependency to do the same if I'm not mistaken?

I imagine that you first implemented the middleware approach but realized you could solve it with dependency injection instead? I'm curious if I'm wrong in my perception?

I have the same question 😉 BTW, thanks for the repo, @Buuntu

pmsoltani avatar Mar 03 '21 21:03 pmsoltani