But what I can tell you is how I fixed a particular problem that I faced while working on the project.
See every new project will come with a new set of challenges, in my case it was the case of third-party integrations. Now integrating a third party application is not a challenge, but in my case, it turns out to be challenging one because of the way it needs to be integrated.
The issue with my case was that I have multiple third-party integrations I want to use based on the user's choice. This choice is stored in the database when a user gets registered in the application. So for example, if User A wants to use ONE and User B for the same use case wants to use TWO. Now we have a single dashboard for both User A and User B, and the same set of functionalities even if one use ONE or the other TWO. So how do we cope up with that?
So to solve this issue of different integration for different users, and a possibility of other third-party integration in the future. So we seek the help of the good old idea of dependency injection, to manage the integrations on a separate area altogether while managing the business logic separately.
Please note that the real integrations are not named "ONE" and "TWO" (yes I follow good coding principles and give meaningful names).
Here, as you can see the corresponding integrations will call the respective files and call their respective business logic behind them.
Now one other question remains. How do we call the corresponding integration?
Above is a screenshot of the "fetchProject" method. The "_fetchService" method calls the "User" collection and fetch the corresponding integration of a particular User and return it within the variable called "service".
And then the corresponding method of "fetchProject" will be called which is in alignment with the user's integration service.
So for example, if User A is the one requesting the "fetchProject" method, then his integration of ONE will be called since the "service" variable now will be "ONE".
Now later if another set of integrations are also introduced all I need to do is write the set of business logic for that particular integration and all is done.
How cool is that ?!
Hope you gained something from this small snippet of mine, happy coding!!!
Comments
Post a Comment