Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Demystifying EE Services

Demystifying EE Services

While the service layer for EE was introduced in version 3, many developers have overlooked or underused this powerful design pattern for creating well-organized, easy to use addons. This talk will go through EE service basics as well as take a deeper dive into use cases and methods of implementation. Additionally, we will cover using services from other addons and EE core services. Attendees will leave this talk ready to build and use services in their own addon development.

Avatar for Julian Fann

Julian Fann

October 26, 2018
Tweet

Other Decks in Programming

Transcript

  1. What are services and why should I care about them?

    Introduction to the EE service layer Consuming EE services Writing your own EE service
  2. a set of software functionalities with a purpose that different

    clients can reuse for different purposes[1] DEFINITION [1] Wikipedia - https://en.wikipedia.org/wiki/Service_(systems_architecture)
  3. is a logical representation of a repeatable business activity that

    has a specified outcome is self-contained may be composed of other services is a “black box” to consumers of the service[2] [2] Open Group - http://opengroup.org/soa/source-book/soa/soa.htm A SERVICE...
  4. Provides a mediation interface between a data layer and a

    request cycle of an application CONTROLLER
  5. The ee() function now* takes an argument for accessing a

    service ee('Config') * Since EE 3.0
  6. Addon Service CP/Alert Service Config Service Consent Service CSV Library

    Encrypt Service Event Service CP/FilePicker Service CP/Filter Service Format Service IP Address Service LivePreview Service Memory Service CP/Modal Service Model Service CP/Pagination Service Permission Service CP/Sidebar Service Spam Service CP/Table Service CP/URL Service Validation Service View Service FIRST-PARTY SERVICES https://docs.expressionengine.com/latest/development/services
  7. return array( 'author' => 'Andrew Weaver', 'author_url' => 'http://brandnewbox.co.uk/', 'name'

    => 'FormGrab', ... 'services' => array( 'Form' => 'Service\Form', ) );
  8. Create leaner primary addon files Write more modular, more easily

    maintainable code Reuse service code across your addon Allow developers to use your service in their own addons WHY CREATE A SERVICE?
  9. Intefaces to APIs (adapter) Encapsulated business logic (facade) Functionality that

    combines data sources (proxy) Model wrappers (controller) WHAT SHOULD YOU MAKE INTO A SERVICE?
  10. Create a Service directory in your addon directory Define your

    addon's namespace in your addon.setup.php Create a service class in the Service directory Register your service in your addon.setup.php SERVICE SETUP
  11. Services make your life easier and your code cleaner Make

    useful things into services Don't depend on another addon's service unless you know it will be installed At the very least, start leveraging core services WRAPPING UP