Brian Vallelunga
Brian Vallelunga

Reputation: 10181

Hooking up custom IManageUnitsOfWork with NServiceBus?

I'm trying to do some performance logging with NServiceBus using a custom IManageUnitsOfWork implementation. Unfortunately, my custom IManageUnitsOfWork is never invoked and I'm not sure why. My current implementation looks like this:

public class UnitsOfWorkManager : IManageUnitsOfWork
{
    private readonly Logger logger;
    private readonly Stopwatch stopwatch;

    public UnitsOfWorkManager()
    {
        this.logger = LogManager.GetCurrentClassLogger();
        this.stopwatch = new Stopwatch();
    }

    public void Begin()
    {
        this.stopwatch.Start();
    }

    public void End(Exception ex = null)
    {
        this.stopwatch.Stop();
        this.logger.Info("HANDLERS ELAPSED DURATION: " + this.stopwatch.ElapsedMilliseconds);
    }
}

I have my Unity container registering the object as normal:

container.RegisterType<IManageUnitsOfWork, UnitsOfWorkManager>();

Is there something else I need to do to get this called? I'm using a Windows Service, not the NSB host. I'm currently using version 3.2.8.

Upvotes: 0

Views: 419

Answers (1)

Christer Unestrand
Christer Unestrand

Reputation: 11

Try adding an instance name to the registration:

container.RegisterType<IManageUnitsOfWork, UnitsOfWorkManager>("UnitsOfWorkManager");

Upvotes: 1

Related Questions