Skip to content

Hook Operator Customization

Furkan Güngör edited this page Dec 22, 2021 · 2 revisions

Customization of Hook Operator

IronHook supports the HttpHookOperator structure by default.

This build can be overridden for custom needs.

For Example; You may want to log while your hook operations are running.

Let's customize.

Step 1

public class CustomizeHookOperator : HttpHookOperator
{
    private readonly ILogger<CustomizeHookOperator> logger;

    public CustomizeHookOperator(IIronHookContext ironHookContext, ILogger<CustomizeHookOperator> logger) : base(ironHookContext)
    {
        this.logger = logger;
    }

    public override Task<IList<HookResponse>> SendHookAsync<T>(Hook hook, List<HookRequest> requests, T data = default)
    {
        logger.LogInformation("Starting Hook");
        return base.SendHookAsync(hook, requests, data);
    }
}

Step 2

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllersWithViews();

    services.AddIronHook(options =>
    {
        options.UseNpgsql(Configuration.GetConnectionString("Default"), opts => opts.UseIronHookNpgsqlMigrations());
    });

    services.AddTransient<IHookOperator, CustomizeHookOperator>();
}
Clone this wiki locally