question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnitOfWorkCommandHandlerDecorator in UserAccess Module Doesn't Get Called.

See original GitHub issue

Hello Kamil,

I thought I have figured the project architecture from end to end and decided to try it out on a side project. I am almost sure I followed your example thoroughly and didn’t miss out anything. But when I tested it by trying out the RegisterUser endpoint, It returns 200 but the user isn’t found at least in the database. I tried to step through the process and realized that all through the process of the step-through, UnitOfWorkCommandHandlerDecorator and ValidationCommandHandlerDecorator were never called. When this line from CommandsExecutor.cs runs - return await mediator.Send(command); , Dispose() of SqlConnectionFactory.cs gets called next. I don’t know why this happens… At some point, the debug was stuck in between Quartz and SerilogLogProvider. I don’t know what I’m missing, and I’ve been on this for days. I was hoping you would point me to the right direction because my frustration is building up. Please help.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
dbeylkhanovcommented, Oct 24, 2020

@kacey90 I had a similar problem with the decorator and in my situation, there are a couple of problems.

The first problem is related to missing registrations of command handlers which are implements ICommandHandler<>. Thereby, MediatR resolved the IRequestHandler<> service from the container and my handlers were skipped. Another problem was in registering the decorator itself. You no need to set serviceType as typeof(ICommandHandler<>), just change it to the typeof(IRequestHandler<>). e.g. builder.RegisterGenericDecorator(typeof(UnitOfWorkCommandHandlerDecorator<>), typeof(IRequestHandler<>)); That new behavior with decorator registering was introduced in the Autofac starting from the v5. Kamil’s infrastructure project uses Autofac v4.9.2 where we have no such problems in registration. See details here

cc @kgrzybek FYI

1reaction
andreyppsccommented, Aug 2, 2021

I’ve managed to do it like this (Autofac 6.2.0):

builder.RegisterGenericDecorator(
    typeof(UnitOfWorkCommandHandlerDecorator<>),
    typeof(IRequestHandler<>),
    context => context.ImplementationType.FullName.EndsWith("CommandHandler"));

builder.RegisterGenericDecorator(
    typeof(UnitOfWorkCommandHandlerWithResultDecorator<,>),
    typeof(IRequestHandler<,>),
    context => context.ImplementationType.FullName.EndsWith("CommandHandler"));
Read more comments on GitHub >

github_iconTop Results From Across the Web

Decorating specific command handlers with unit of work
When a command or any other dependency needs an IUnitOfWork , they will get the DelayedUnitOfWorkProxy , and it is injected with a...
Read more >
Repository and Unit Of Work : r/dotnet
I understand CQRS as being a strategy to separate Commands that affect change from Queries that affect no change but only returns data....
Read more >
Implementing the microservice application layer using ...
Understand the Dependency Injection and the Mediator patterns and their implementation details in the Web API application layer.
Read more >
Command Query Separation (CQS) - A simple but powerful ...
This tutorial demonstrates how to design software using the Command Query Separation (CQS) pattern. We will create a console application and ...
Read more >
Maple512/modular-monolith-with-ddd
To avoid calling commit on every handler, UnitOfWorkCommandHandlerDecorator is used. It additionally marks InternalCommand as processed (if it is Internal ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found