python-dependency-injector icon indicating copy to clipboard operation
python-dependency-injector copied to clipboard

Best practices for container and service placement in a flask app?

Open prchristie opened this issue 2 years ago • 1 comments

Pretty general question that is probably up for debate to the public.

I have a file structure as such

image

You can see that containers is in the top level with the configuration, along with the services. The ingest folder is a flask app that contains views that are being injected into. All views will be in a folder alike that ingest folder.

My question is; should the containers configuration in containers.py be in a top level directory and have only one of them, or one for each subapp (like ingest)? Should services specific to a subapp be placed in the folder of that subapp (so instead we would have ingest/services)?

prchristie avatar May 03 '22 05:05 prchristie

In my opinion Best Practices are there to stop problems from happening. They don't solve the problems your app is built to solve, so best practices should be subservient to the overall problem this app is solving. With that being said, there is no definitive reason subapp containers could not work. It might be a little more confusing but a sufficiently complex app might have that requirement of subapps with different dependency injector strategies. I would refer you to this website Why Do Our Designs Go Wrong? as for how you should approach dependency management.

bmgarness avatar Jul 28 '22 14:07 bmgarness