I need to implement logic which will be retrieve data from some remote datasource. And now I need to decide - which concept should I need: Provider, Repository or Service.
Actually I do not understand very well all great difference between that. Yeas, I know that repository is something more data specific and should not contain any business logic. Provider for other hand may contain some business rules in addition to manage data. And Service also could contain some business logic in addition to manage data. Then what is the difference between Service and Provider.
From the other point of view, I think that using service is better approach to show that it's an abstraction for remote access.
In conclusion: All this approaches looks reasonable and I completely confused with it. Will be pretty much appreciate if someone will help me with it.
A repository handles the data access and the service calls into it after performing any business logic needed.
What this is saying, is a Model opens access to a database table. It also allows you to relate to other models to pull out data without having to write individual queries. A repository allows you to handle a Model without having to write massive queries inside of a controller.
The main purpose of a repository is to store a set of files, as well as the history of changes made to those files.
A service repository is a catalogue in which you can see what services are available on a network. For instance, imagine you have a service oriented architecture in a bank. In the beginning when the number of services is low it might be possible to keep track of what services are running where in spreadsheets etc.
The Repository and Service are not mutually exclusive. In fact, they are often used together.
The service layer sits on top of your domain objects and provides a coarse-grained interface for business operations. It usually describes the use cases of your application. The service layer uses repositories for obtaining your domain objects and delegates further execution to them where possible.
The Repository acts like a collection of persistent domain objects. It provides methods for finding the right objects using some criteria. It also provides methods for saving those objects.
The implementations of repository in the wild vary quite a bit. Repositories could provide methods like
List<Person> findPersonByName(String name)
or a more generic approach with criteria objects
List<Person> find(Criteria criteria)
Additional reading: service layer, repository
I'm not familiar with the Provider pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With