BlackBoxVision / typescript-hapi-starter

🚀 Starter for building APIs with Hapi + Typescript!
MIT License
128 stars 28 forks source link

First pass on container implementation #13

Closed jcloutz closed 5 years ago

jcloutz commented 6 years ago

Now that I have some free time after the holidays I wanted to take a crack at implementing dependency injection via Inversify as was discussed in #5. This is the first time that I've used it and any feedback would be welcome.

Things I'm not sure about:

Changes:

JonatanSalas commented 6 years ago

@jcloutz well, after all thanks for you contribution.- It's really well appreciated.

I will start answering your doubts:

Things I'm not sure about:

You - Is it too much to use the container for everything? Should it only be used for resolving services, and repositories, etc..

Me - Maybe yes, maybe not. Depending on the case, using the container for all would be over engineer. For the case that this is a starter kit for project bootstrap, I would prefer to keep it simple, and only use it for Services and Repositories.

You - Interface organization: specification should they be in a single interface file? Or should they be broken up into their respective folders i.e. common, api/users, api/articles.

Me - I consider that they should be broken up in their respective folders.

You - Is the resolver redundant when using the container? It seems like it might make more sense to inject the repository directly into the controller since it's basically just proxying that functionality.

Me - Yes, it's redundant because know that you use container it's working as a proxy, like you said.

You - Would it make sense to use something like this Config to enable environment specific configs. It would probably help with testing.

Me - I would prefer relying on a more known solution, like the usage of .env files. Do you agree with that?

My ideas behind this project:

I would like to focus on set of basic features, and then, use this project as a template to develop some kind of cli like create-react-app.

Well, that's all I have to say. I will review, and test a little bit better the code on my local machine, and sure this PR would be merged.

jcloutz commented 6 years ago

There are a few things that you should consider "broken" in this PR that I haven't had time to fix. Also some things that I learned through the process and after I made this PR by building a small app with it. At this point I have some mixed feelings on this PR to be honest.

JonatanSalas commented 5 years ago

Closing this PR, since I want to keep a more functional approach on the code. Implementing IoC may introduce some complexity to those starting with node and Typescript.