Skip to content

Filters

Ian Johnson edited this page Sep 7, 2018 · 2 revisions

Filters

EasyRpc provides the ability to apply filters to your rpc calls by implementing one or both of the interfaces ICallExecuteFilter and ICallExceptionFilter.

app.UseJsonRpc("", api => 
{
   api.ApplyFilter<CustomFilter>();
   api.Expose<IntMathService>();
});

public class CustomFilter : ICallExecuteFilter, ICallExceptionFilter
{
   public void AfterExecute(ICallExecutionContext context)
   {
   }

   public void BeforeExecute(ICallExecutionContext context)
   {
   }

   public void HandleException(ICallExecutionContext context, Exception exception)
   {
   }   
}

Attributes

Sometimes it's easier to apply filters using attributes. They can be applied at the method, class, or assembly level.

public class CustomFilterAttribute : RpcFilterAttribute
{
  public CustomFilterAttribute() : base(typeof(CustomFilter)) { }  
}

public class SomeService
{
  [CustomFilter]
  public int SomeMethod() => 1;
}
Clone this wiki locally