I use mediatr nuget package and autofac in an api .net 6.
I would like to decorate a specific command only of the IRequestHandler<T,K> of the Mediator, and not all the commands that I have.
For example, i have the IRequestHandler<UpdateWallet, AmountCalculation> And i would like to decorate only this command handler with a class AmountCalculationDecorator.
class AmountCalculationDecorator: IRequestHandler<UpdateWallet, AmountCalculation>
{
private readonly IRequestHandler<UpdateWallet, AmountCalculation> _decorated;
public AmountCalculationDecorator(
IRequestHandler<UpdateWallet, AmountCalculation> decorated)
{
_decorated = decorated;
}
public async Task<AmountCalculation> Handle(UpdateWallet request, CancellationToken cancellationToken)
{
// mpla mpla
}
}
Now i try to register this decorator in the autofac di.
public partial class ApplicationModule : Autofac.Module
{
protected override void Load(ContainerBuilder builder)
{
var thisAssembly = Assembly.GetExecutingAssembly();
builder
.RegisterMediatR(thisAssembly);
builder
.RegisterDecorator<AmountCalculationDecorator, IRequestHandler<UpdateWallet, AmountCalculation>>();
}
}
But i get
Circular component dependency detected:AmountCalculationDecorator.
How can achieve this implementation?