Skip to main content
Version: v3.0.0

Create custom events

Create Custom Events#

We allow you to create custom events next to the official Azure SDK event schemas.

The official SDK provides a class called EventGridEvent which provides your event data as an ordinary .NET object. We provide a variation of the official EventGridEvent which provides your data as a typed instance instead.

This makes sure that your new custom events are both type-safe and are supported by any official functions that use the official EventGridEvent.

using Arcus.EventGrid.Contracts;using Newtonsoft.Json;
public class CarEventData{    public CarEventData(string licensePlate)    {        LicensePlate = licensePlate;    }
    public string LicensePlate { get; }}
public class NewCarRegistered : EventGridEvent<CarEventData>{    private const string DefaultDataVersion = "1",                          DefaultEventType = "Arcus.Samples.Cars.NewCarRegistered";
        // `JsonConstructor` attribute is not necessary but can help as documentation for the event.        [JsonConstructor]        private NewCarRegistered()         {        }
        public NewCarRegistered(string id, string licensePlate) : this(id, "New registered car", licensePlate)        {        }
        public NewCarRegistered(string id, string subject, string licensePlate)             : base(id, subject, new CarEventData(licensePlate), DefaultDataVersion, DefaultEventType)         {        }}

Read "Deserializing Events" for information on how custom events are deserialized.