Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@alexeyzimarev
Last active July 12, 2017 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexeyzimarev/ae92e6c486b8b360d764588fa44a990d to your computer and use it in GitHub Desktop.
Save alexeyzimarev/ae92e6c486b8b360d764588fa44a990d to your computer and use it in GitHub Desktop.
Using this base class you can handle your messages without extracting them first from the context. Context is still available.
using System.Threading.Tasks;
using MassTransit;
namespace Demo.MassTransit
{
public abstract class BaseHandler<T> : IConsumer<T> where T : class
{
protected ConsumeContext<T> Context { get; private set; }
public abstract Task Handle(T message);
public Task Consume(ConsumeContext<T> context)
{
Context = context;
return Handle(context.Message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment