---
title: Resolver
summary: API reference for Resolver.
status: draft
owner: <owner>
last_reviewed: 2026-07-23
library: SAIF.Framework.DNS
reference_type: package
---

# Resolver

`Resolver` is the static entry-point facade for performing DNS lookups over UDP. It builds no state of its own (it is `sealed` with a private constructor) and exposes two static methods: a generic `Lookup` and a convenience `MXLookup`.

## Purpose
- Provide the primary caller-facing API for sending a `Request` to a DNS server and obtaining a parsed `Response`.
- Provide a convenience wrapper for the common case of retrieving and preference-sorting MX records for a domain.
- Own the low-level UDP socket transfer and retry logic used by all lookups.

## Context
- Namespace: `SAIF.Framework.DNS`
- Assembly/package: `SAIF.BOF.Framework.DNS` (bundled as source into the `SAIF.BOF.Framework` NuGet package)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| MXLookup | `public static MXRecord[] MXLookup(string domain, IPAddress dnsServer)` | Builds an MX/`IN` request for `domain`, performs the lookup, and returns matching MX answers sorted ascending by preference (or `null` if no response). |
| Lookup | `public static Response Lookup(Request request, IPAddress dnsServer)` | Serializes `request`, sends it via UDP to `dnsServer` on port 53 with retry, and returns the parsed `Response`. |

## Behavioral notes
- `Resolver` cannot be instantiated; its constructor is private and the class is `sealed`, consistent with a stateless static utility.
- `MXLookup` and `Lookup` both throw `ArgumentNullException` if any required argument is `null`.
- `Lookup` communicates over UDP to port 53 with up to 2 retries and a 1-second receive timeout per attempt, throwing `NoResponseException` if no matching reply is received after all attempts.
- A UDP reply is only accepted if its stamped 2-byte transaction id matches the outgoing request; otherwise the attempt is treated as unanswered and the retry loop continues.
- Enforces [BR-001](../../business-rules.md#br-001-lookup-arguments-must-not-be-null), [BR-005](../../business-rules.md#br-005-udp-requests-are-retried-up-to-two-additional-times-before-failing), [BR-006](../../business-rules.md#br-006-udp-replies-are-only-accepted-when-the-transaction-id-matches), and [BR-008](../../business-rules.md#br-008-mx-records-are-ordered-by-ascending-preference).

## Constraints and usage notes
- Only one `Question` per `Request` is recommended, since many DNS servers do not support multi-question requests*.
- Callers should be prepared to catch `NoResponseException` (transport failure) and `InvalidResponseException` (malformed reply) separately, since they signal distinct failure modes.

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts.

## Sources
- SAIF.Framework.DNS\Resolver.cs
