Skip to content

Instantly share code, notes, and snippets.

@jonasdw
Last active May 30, 2018 06:45
Show Gist options
  • Save jonasdw/9dd80ff00d59d6f371a2adcfc72a1118 to your computer and use it in GitHub Desktop.
Save jonasdw/9dd80ff00d59d6f371a2adcfc72a1118 to your computer and use it in GitHub Desktop.
public class ExtendCommandWithData<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
// do something with request to add the data
//if (typeof(TRequest).IsAssignableFrom(typeof(ICommand)))
//{
// request.AddUserId("id");
//}
var response = await next();
return response;
}
}
public interface ICommand
{
string UserId { get; set; }
string UserIpAdress { get; set; }
}
@hagbarddenstore
Copy link

var command = request as ICommand;

if (command != null)
{
  command.AddUserid("id");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment