TaskFactory¶
Implements ITaskFactory, creating marketing and underwriting Task records against a policy after validating the incoming request. It depends on IRepositoryFactory for repository access, IUserProfileService (resolved once at construction into a cached current-user snapshot), IValidationService for FluentValidation-based request validation, and ITaskQueryProvider for resolving the target policy and task category.
Purpose¶
- Validates a
CreatePolicyTaskRequestand throwsSaifValidationExceptionwhen it fails validation, preventing invalid tasks from being persisted. - Creates a marketing task ("MA" category) or an underwriting task ("U" category) for a policy, defaulting priority/source/action from the resolved task category.
- Stamps new tasks with the current user as both create and update user.
Context¶
- Namespace:
SAIF.Services.Tasks - Assembly/package:
SAIF.Services(packaged inside theSAIF.SAIFCode.CoreNuGet package)
Public members¶
| Member | Signature | Purpose |
|---|---|---|
| TaskFactory(...) | public TaskFactory(IRepositoryFactory repoFactory, IUserProfileService profile, IValidationService validation, ITaskQueryProvider taskQueryProvider) |
Validates repoFactory, profile, and validation are non-null via Enforce.ArgumentNotNull, wires in the query provider, and captures the current user once for reuse by later task-creation calls. |
| CreateMarketingTask | public long CreateMarketingTask(CreatePolicyTaskRequest request) |
Validates the request, creates a task in the "MA" (marketing) category linked to the requested policy, adds it to the repository, and returns its new ID; throws SaifValidationException on invalid input. |
| CreateUnderwritingTask | public long CreateUnderwritingTask(CreatePolicyTaskRequest request) |
Validates the request, creates a task in the "U" (underwriting) category linked to the requested policy, adds it to the repository, and returns its new ID; throws SaifValidationException on invalid input. |
Behavioral notes¶
- The current user is resolved once in the constructor (
profile.GetCurrentUser()) and cached for the lifetime of the factory instance, so the create/update user stamped on tasks reflects the user at construction time rather than at each call*. - Both task-creation methods run the same validation pipeline via
_validationService.Validate(request)before touching the repository, so no partial task is added to the repository when the request is invalid. - New tasks inherit their priority, source, and default action entirely from the resolved
TaskCategory("MA"or"U") rather than accepting them as request parameters.
Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts. Statements marked with ** could not be confirmed; treat as unknown until verified.
Sources¶
- Services/SAIF.Services/Tasks/TaskFactory.cs