hades200082 / template-app-infrastructure

MIT No Attribution
0 stars 0 forks source link

Alternative to singleton for api services #22

Closed hades200082 closed 1 year ago

hades200082 commented 1 year ago

@styles102 This is an alternative approach to the singleton API services that I think might be simpler and resolves the issues we discussed nicely.

Thoughts?

styles102 commented 1 year ago

@hades200082 either or really, like I said yesterday I think we just need to pick a route and see how it works for us. We can always pivot if we find it isn't working for us.

hades200082 commented 1 year ago

@styles102 From talking with the devs in the Typescript discord, the approach in this PR is better than using classes as "singleton" classes are not really that helpful in TS modules anyway.

I think the approach in this PR is simpler, easier to onboard new devs into and potentially more flexible in the long term. It also seems like less boilerplate code to create a new API resource service this way.

Overall it seems from the discussion on Discord and further reading on the web that there is no one correct answer to this. There is no one best practice. It depends on the use case and personal preference.

I'll finalise this PR later, solve the merge conflicts and get you to review it again before merging.

hades200082 commented 1 year ago

@styles102 Ready for review when you get time

hades200082 commented 1 year ago

@styles102 Also looking for your review on this now :)