The triggers are a good way to execute an action when a Type-DB method is called.

How to Use ?

Method to use in the fluent configuration builder: .UseTriggers()

Basic Example

This simple example show the usage of Triggers.

using (var tdb = new TypeDB.Core(Mode.Standalone)
.UseTriggers(new Trigger(MethodType.Set, (dto) =>
Console.WriteLine($"Hey you have set the '{dto.Key}' entity !");
// Hey you have set the 'hello' entity !
using (var testdb = tdb.OpenDatabase("test", true))
testdb.Set<string>("hello", "world");

About Callback and DTO

When you create a trigger when new Trigger() you need to give a callback as the second parameter, this callback return a DTO object that contain the collection, the key and the value that is concerned.

If you want to use DTO object in a non-anonymous function you need to add this reference:

using TypeDB.Interception;

Methods that you can Trigger

You can place a Trigger on all of this methods:

  • MethodType.Set

  • MethodType.Get

  • MethodType.Increment

  • MethodType.Decrement

  • MethodType.Lock

  • MethodType.Unlock

  • MethodType.Expire

  • MethodType.Exist

  • MethodType.Filter

  • MethodType.Drop

  • MethodType.Clear

Triggers in the Future

We have intention to add more triggering capabilities other than just methods execution.