dependency-injectionmasstransit

How to resolve IFilter from DI in Masstransit


I'm following the Masstransit documentation about creating message type filters but there I see the Filter instance is created manually:

public class ExceptionLoggerSpecification<T> :
    IPipeSpecification<T>
    where T : class, PipeContext
{
    public IEnumerable<ValidationResult> Validate()
    {
        return Enumerable.Empty<ValidationResult>();
    }

    public void Apply(IPipeBuilder<T> builder)
    {
        builder.AddFilter(new ExceptionLoggerFilter<T>());
    }
}

My question is, how can the instantiation be handled by Dependency Injection? For the case the filter has dependencies that need to be resolved.


Solution

  • You should use scoped filters if you want to resolve filters from DI.

    Documentation.