Base solution for your next web application
Open Closed

Disable UnitofWork in an AppService Method #2220


User avatar
0
george created

Hi, I need to generate a reference no for each transaction. The reference no. should not be repeated in any of the cases. Even if there is any exception is occurred at any point of the method. If a new reference no. is updated, it should not be rolled back.

So, I've created my method as follows:

[UnitOfWork(IsDisabled = true)]
        public OnlinePaymentReferenceNumberListDto GetReferenceNumber()
        {
            var currentReferenceNo = _referenceNoRepository.GetAll().FirstOrDefault();

            var nextReferenceNo = currentReferenceNo.MapTo<OnlinePaymentReferenceNumber>();
            nextReferenceNo.Year = DateTime.Now.ToString("yy");
            nextReferenceNo.Month = DateTime.Now.ToString("MM");
            nextReferenceNo.Number = nextReferenceNo.Number + 1;
            _referenceNoRepository.Update(nextReferenceNo);

            return currentReferenceNo.MapTo<OnlinePaymentReferenceNumberListDto>();
        }

But the problem is, I'm calling this method from another appservice. I've read from your pretty good documentation that, if a unit of work method calls this methode, disabling this method is ignored and it uses the same unit of work with the caller method.

So, I think, my requirement will not be satisfied. What can we do for this?


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Appservices shouldn't call each other. You can create a domain service for common things used in two app services and use that domain service in two of your app services.