I am trying to apply the decorator pattern to wrap all needed methods from a service in an exception handler, to increase testability and to keep the code clean.
The callchain is like this:
- EntityService.UpdateEntities (gets List of entities, passes to next method using foreach)
- EntityService.UpdateSingleEntity (executes the actual update)
UpdateEntities:
var entities = await _context.Entities.Where(criteria).ToListAsync(cancellationToken);
entities.ForEach(async e => await UpdateEntity(e));
Here, UpdateEntity from the same service is called, without first calling the decorator
These methods need to be split because I will need the last method in another part of the software
Problem is, because I am calling the method from the same service, the decorator is skipped. Of course, if I would inject the service into itself using constructor injection, a stack overflow exception would occur.
How would I go about fixing this issue?