You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Framework/Connected.Services/Middleware/FunctionMiddleware.cs

27 lines
616 B

namespace Connected.Services.Middleware
{
public abstract class FunctionMiddleware<TArgs, TReturnValue> : ServiceMiddleware<TArgs>, IFunctionMiddleware<TArgs, TReturnValue>
{
protected TArgs? Arguments { get; private set; }
public async Task<TReturnValue?> Invoke(TArgs? args, TReturnValue? result)
{
Arguments = args;
await OnValidate();
return await OnInvoke(result);
}
protected virtual async Task<TReturnValue?> OnInvoke(TReturnValue? result)
{
await Task.CompletedTask;
return result;
}
protected virtual async Task OnValidate()
{
await Task.CompletedTask;
}
}
}