A hook is an extension that is triggered in response to one, or more, system events. See Weavy.Core.Events for a list of available events.


To add a hook that responds to an event you should first add a class that inherits from Hook. Your class should also implement the IHook<TEvent> interface for the event you want to handle. A good convention to follow is placing your class in the Models folder. In the example below we add a hook that listens to the AfterInsertComment event and trashes the inserted comment if it contains certain keywords.


using NLog;

using System;

using System.Collections.Generic;

using System.ComponentModel.DataAnnotations;

using System.Runtime.InteropServices;

using System.Threading.Tasks;

using Weavy.Core.Events;

using Weavy.Core.Models;

using Weavy.Core.Services;


namespace Weavy.Models {




   [Plugin(Description = "A hook that automatically trashes comments with certain keywords.")]

   public class CommentFilterHook : Hook, IHook<AfterInsertComment> {


       private static readonly Logger _log = LogManager.GetCurrentClassLogger();




       [Display(Name = "Keywords", Description = "A list of keywords to look for.")]

       public List<string> Keywords { get; set; }


       /// <summary>

       /// Trash comment if it contains one of the specified keywords.

       /// </summary>

       /// <param name="e"></param>

       public void Handle(AfterInsertComment e) {

           if (Keywords != null) {

               foreach (var keyword in Keywords) {

                   if (e.Inserted.Text.IndexOf(keyword, StringComparison.OrdinalIgnoreCase) >= 0) {

                       var trashed = CommentService.Trash(e.Inserted.Id);

                       _log.Warn($"Trashed comment '{trashed.Text}' with keyword '{keyword}'");








Class attributes 

As shown above, hooks must be decorated with the [Serializable] and [Guid] attributes.

Make sure to give your class a unique Guid, otherwise it will not be recognized by Weavy.


To further customize your hook you can also decorate it with the[Plugin] attribute. Some of the properties you can set are:

  • Icon – name of an icon to use when displaying the daemon.
  • Color – the color to use for the icon.
  • Name – display name for the content item, e.g. “Comment filter”.
  • Description – a description to use for the daemon, e.g “A hook that automatically trashes comments with certain keywords.”.


Hook fields are pieces of information that can be added to a hook. This can be useful if your hook requires some kind of configuration or settings. Hook fields have a name and a type. In the example above, we added a field for storing the keywords not allowed in comments.

For a property to be considered a hook field, it must be declared as public read-write, i.e. the property has the public access modifier and have both a get and a set accessor.

Hook fields must also have one of the following supported types:

  • enum
  • byte
  • short
  • int
  • long
  • bool
  • double
  • float
  • string
  • Guid
  • DateTime
  • TimeSpan

Nullables and Lists of the above types are also supported, e.g. int?, List<string> and List<DateTime?>.

Field attributes 

By decorating your fields with one, or more, of the following attributes you can customize how the field is displayed, edited and/or validated.


By default, Weavy will look at the property type (in this case IList<string>) when deciding which editor to use for the field. By decorating a field with the [DataType] attribute you can specify an additional type to associate with the field. This value will then be used by the UI to determine which editor to use for the field.


public List<string> Keywords { get; set; }

Here we specify that the Keywords field should use the Tags editor.


The [Display] attribute lets you specify a name and description to use for the field.

[Display(Name = "Keywords", Description = "A list of keywords to look for.")]

public List<string> Keywords { get; set; }


By adding one, or more, [Validation] attributes to your fields you can control how they are validated.


public List<string> Keywords { get; set; }

Here we specify that the Keywords property is required.

For full control of validation you can let your class implement IValidatableObject and add your own validation logic.


If a hook requires some kind of configuration settings, like the Keywords property in our CommentFilterHook, you can navigate to /manage/hooks/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX where the last segment should be replaced with the Guid of your Hook, in this case CF2303B5-A8B1-4F91-8029-9F464338A8DC for the CommentFilterHook.