Code Monkey home page Code Monkey logo

Comments (3)

kauemurakami avatar kauemurakami commented on September 7, 2024 4

Hello @nxcco !
The difference between providers and services are basically:

  • Providers are the source of your data, be it an API or a DB for example, then it provides the necessary information for your application.

  • Services are application services, more specifically our GetXServices, which are services / features that will be arranged by more than one part of the application, different from our controllers which, in this context, are available for each module.
    I have two good examples of services for you.

  • What I use most in this approach is an auth_service for example, note that each service may or may not have a repository, it depends on whether or not it has integration with providers, in the case of auth, it probably will, and in this service I concentrate everything related to authentication, such as registration, login, logout, I can use it and its respective functions of different controllers. Example, controller login will consume this service to log in, in the profile there is a button to log out and you will call this same service only with Get.find, another good use is to keep something in it, in case I keep a user or a token for example, right in all the controllers that you need this object it will already be available, without any getUser or something, soon it would take the weight of a call getUser from the controller of the profile module for example, besides you want to access his id in several other cases, for example, and your service will be available there.

  • Another good example that I used in the examples in this doc is the app_config_service.
    Imagine that, just like in the example, you decide to change the theme of the app, and save it, and retrieve from GetStorage which is the last option marked to remember when reopening the app.
    Soon you can do this from one or more places, at the same time wanting to recover this state to leave a white or black button, for example and this service will be available, just use Get.find.
    End that is why our services are at this level of the application, in date, as it serves all modules.
    See this example.

  • As mentioned, controllers are responsible for controlling the module in which it is assigned, and services are not necessarily exclusive, you can call them on any controller, as long as the service is alive in memory, so it is a level above our modules , and the controllers are internal to each module, in other words, each module is the responsibility of a controller, and it is removed from memory at the right time, Services are not exclusive, you can mix in more than one module, and stay alive in memory until the app closes or you give auth_service.delete()

I will leave the issue open for today, in case there are any more questions.

from getx_pattern.

kauemurakami avatar kauemurakami commented on September 7, 2024 2

Whenever you need us, we'll be here, see you later. xD

from getx_pattern.

nxcco avatar nxcco commented on September 7, 2024 1

Thank you for taking the time to clear things up!😄

from getx_pattern.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.