Switch branches/tags
Nothing to show
Find file Copy path
b70d4b0 Dec 14, 2018
1 contributor

Users who have contributed to this file

51 lines (25 sloc) 1.99 KB


Invocables are ubiquitous classes that all of Coravel's features understand how to work with.

Invocables allow you to define specific self-contained jobs within your system. Since Coravel "understands" how to use invocables, you can do cool stuff like schedule or queue them using a super terse syntax.

Creating An Invocable

Creating an invocable uses the shared interface Coravel.Invocable.IInvocable.

Using .NET Core's dependency injection services, your invocables will have all their dependencies injected whenever they are executed.

You may use the Coravel Cli to generate a new invocable.

Alternatively, to create an invocable by hand:

  1. Implement the interface Coravel.Invocable.IInvocable in your class.

  2. In your invocable's constructor, inject any types that are available from your application's service provider.

  3. Make sure that your invocable itself is available in the service container.


Example: Generating A Daily Report And Emailing To Users

In this example, SendDailyReportsEmailJob is an invocable that was created by us. It handles getting data (via some repository that was injected via DI) and generating an e-mail, etc.

Coravel Invocable Sample

A sample implementation of the SendDailyReportsEmailJob class might look something like this (which is using Coravel's Mailer to send e-mail):

Coravel Invocable Sample

Example: Trigger Long Running Calculations In Background

You might have a use-case where - from an admin screen - you want to have an HTML button that will fire off an expensive calculation - at least too long to let your users wait for it to finish. Once completed, it might save the results to a database.

Assuming you created an invocable DoExpensiveCalculationAndStoreInDB, you could run it like this:

Coravel Invocable Sample