XF 2.2 Best practice for shared functions

stromb0li

Active member
This is an ultra generic question, but is there documentation on when a repository or service class should be defined?

I have a few functions I'd like to share across public and admin controller classes, curious what location I should place them in as best practice.
 
Last edited:
Repositories are generally (but not exclusively) used for abstracting database operations.

Service classes are useful for more complex operations where there is a preparation step and then an execution step (eg sending mail).

You don't have to use either - you could just create a standalone utility class.

I also sometimes use SubContainers when I want to encapsulate a bunch of code that requires some dependency injection - which can also be useful for managing standalone utility classes if they also have dependencies you need to inject. See this post: https://xenforo.com/community/threa...ependency-injection-in-xf.195587/post-1523025
 
Top Bottom