Skip to content

Hook Service Customization

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

Customization of Hook Service

If HookService is not enough for you and you want to customize it, you should create a class that inherits IHookService.

public class CustomizeHookService : IHookService
{
    public Task<Hook> AddAsync(Hook hook)
    {
        throw new NotImplementedException();
    }

    public Task<HookRequest> AddRequestAsync(HookRequest request)
    {
        throw new NotImplementedException();
    }

    public Task<Hook> FindHookAsync(string key, string tenantId)
    {
        throw new NotImplementedException();
    }

    public Task<List<Hook>> GetAsync(Expression<Func<Hook, bool>> expression)
    {
        throw new NotImplementedException();
    }

    public Task<List<HookLog>> GetHookLogsAsync(Guid hookRequestId)
    {
        throw new NotImplementedException();
    }

    public Task<List<HookRequest>> GetHookRequestsAsync(Guid hookId)
    {
        throw new NotImplementedException();
    }

    public Task<IList<HookResponse>> RaiseHookAsync(string key, string tenantId, object data)
    {
        throw new NotImplementedException();
    }

    public Task RemoveAsync(Guid hookId)
    {
        throw new NotImplementedException();
    }

    public Task RemoveRequestAsync(Guid hookRequestId)
    {
        throw new NotImplementedException();
    }

    public Task<Hook> UpdateAsync(Hook hook)
    {
        throw new NotImplementedException();
    }
}

To be able to use it with Dependency Injection, you must add it as a Transient in Startup.cs.

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

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

    services.AddTransient<IHookService, CustomizeHookService>();

}

Or you can inherit from the DefaultHookService class and override the methods you want.

public class CustomizeHookService : DefaultHookService
{
    public CustomizeHookService(IIronHookContextdbContext, IHookOperator hookOperator) : base(dbContext, hookOperator)
    {
    }

    public override Task<Hook> AddAsync(Hook hook)
    {
        return base.AddAsync(hook);
    }
}

To be able to use it with Dependency Injection, you must add it as a Transient in Startup.cs.

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

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

    services.AddTransient<IHookService, CustomizeHookService>();

}
Clone this wiki locally