If the interface is empty, then this is the marker interface .
It can be used to apply class constraints, outside the class. According to the example below, you can restrict the decorator to only decorate handlers with IProcessor.
A very important reason is to use a decorator:
, :
public interface IProcessor
{
int Id { get; }
DateTime Date { get; }
}
IProcessor, , Id Date:
public sealed class HandlerLogger<in T> where T : IProcessor
{
private readonly ILogger logger;
private readonly IHandlerLogger<T> decorated;
public HandlerLogger(
ILogger logger,
IHandlerLogger<T> decorated)
{
this.logger = logger;
this.decorated = decorated;
}
public void Handle(T command)
{
this.logger.Log(command.Id, command.Date, typeof(T).Name);
this.decorated.Handle(command);
}
}