Skip to main content

How to create and invoke services?

How to create a service?

Create a class, include some Convenient Service configuration, define the result method 🙂.

Here is the minimal example.

class Service
include ConvenientService::Standard::Config

def result
success
end
end

How to invoke a service?

There a two ways to do it.

First one - using the class method result.

result = Service.result

Second one - using the instance method result.

service = Service.new

result = service.result
info

Most of the time you will utilize the class method variant (Service.result).

But keep in my mind, that allocating a service instance may be useful when it is needed to delay result calculation.