---
title: BatchProcessingService
summary: API reference for BatchProcessingService.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-24
library: SAIF.Services
reference_type: package
---

# BatchProcessingService

Implements `IBatchProcessingService`, tracking the last successful run date for named batch modules so batch jobs can resume from where they left off. It depends only on `IUnitOfWork` for `BatchProcessLog` repository access.

## Purpose
- Retrieves the recorded last-run date for a named batch module, or a caller-supplied default when no record exists yet.
- Inserts or updates a module's run-date record within a transaction.

## Context
- Namespace: `SAIF.Services.BatchProcessing`
- Assembly/package: `SAIF.Services` (packaged inside the `SAIF.SAIFCode.Core` NuGet package)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| BatchProcessingService(...) | `public BatchProcessingService(IUnitOfWork unitOfWork)` | Validates `unitOfWork` is non-null via `Enforce.ArgumentNotNull` and wires in a cached `BatchProcessLog` repository. |
| GetRunDate | `public DateTime GetRunDate(string moduleName, DateTime defaultValue)` | Returns the recorded `RunDate` for the named module, or `defaultValue` if no `BatchProcessLog` row exists for it. |
| UpdateRunDate | `public void UpdateRunDate(string moduleName, DateTime runDate)` | Within a transaction, inserts a new `BatchProcessLog` row for the module if none exists, or updates the existing row's `RunDate`. |

## Behavioral notes
- `UpdateRunDate` performs an upsert keyed on `moduleName`: it looks up the existing row and either adds or updates, sparing callers from having to know whether the module has run before.
- The repository instance is resolved once in the constructor and reused for all subsequent calls on the service instance.

## Sources
- Services/SAIF.Services/BatchProcessing/BatchProcessingService.cs
