DragonByte Tech
Well-known member
I think I asked something similar back on the XF2 demo board, but I can't seem to find the thread right now.
TL;DR: What is the distinct use-case difference between these three methods of creating application logic?
Details:
I've had a look at the Abstract classes for Repository and Service, as well as the method of instantiating a Repository and a Service in the
So you could do
The difference doesn't appear to be in terms of read vs write either, as I'm seeing "update" operations in public functions (e.g.
Maybe I'm taking this way too seriously but when I'm writing XF2-only applications, I want to do it right, so I want to learn this and all the other intricacies of XF2
Fillip
TL;DR: What is the distinct use-case difference between these three methods of creating application logic?
Details:
I've had a look at the Abstract classes for Repository and Service, as well as the method of instantiating a Repository and a Service in the
\XF
and \XF\App
classes. From what I can tell, the only difference is that a Service allows you to pass arguments to the constructor whereas a Repository does not.So you could do
$service = \XF::service('MyAddon:SomeService', $foo, $bar);
for a Service, but for a Repository you would have to do
PHP:
$repository = \XF::repository('MyAddon:SomeRepo');
$repository->setFoo($foo);
$repository->setBar($bar);
The difference doesn't appear to be in terms of read vs write either, as I'm seeing "update" operations in public functions (e.g.
public function updateTrophiesForUser(\XF\Entity\User $user, $userTrophies = null, $trophies = null)
), so the notion that a Repository was only the equivalent of "complex to construct, but frequently executed, database reads" portion of the old XF1 Model system appears to be out the window.Maybe I'm taking this way too seriously but when I'm writing XF2-only applications, I want to do it right, so I want to learn this and all the other intricacies of XF2
Fillip