Design your class constructor to ask for the necessary dependencies rather than creating them or using
_elgg_services(). The service provider’s setFactory() method provides access to the service provider
instance in your factory method.

Here’s an example of a foo service factory, injecting the config and db services into the constructor:

By default, services registered on the service provider are “shared”, meaning the service provider
will store the created instance for the rest of the request, and serve that same instance to all
who request the property.

If you need developers to be able to construct objects that are pre-wired to Elgg services, you may
need to add a public factory method to Elgg\Application. Here’s an example that returns a new
instance using internal Elgg services: