Skip to main content

arolariu.Backend.Domain.Invoices.Services.Foundation.InvoiceAnalysis

arolariu.Backend.Domain.Invoices

arolariu.Backend.Domain.Invoices.Services.Foundation.InvoiceAnalysis Namespace

Classes

InvoiceAnalysisFoundationService Class

The invoice analysis foundation service interface represents the foundation analysis service for the invoice domain.

public class InvoiceAnalysisFoundationService : arolariu.Backend.Domain.Invoices.Services.Foundation.InvoiceAnalysis.IInvoiceAnalysisFoundationService

Inheritance System.Object 🡒 InvoiceAnalysisFoundationService

Implements IInvoiceAnalysisFoundationService

Constructors

InvoiceAnalysisFoundationService(IClassifierBroker, IFormRecognizerBroker, ILoggerFactory) Constructor

DI Constructor.

public InvoiceAnalysisFoundationService(arolariu.Backend.Domain.Invoices.Brokers.AnalysisBrokers.ClassifierBroker.IClassifierBroker analysisBroker, arolariu.Backend.Domain.Invoices.Brokers.AnalysisBrokers.IdentifierBroker.IFormRecognizerBroker receiptRecognizerBroker, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory);

Parameters

analysisBroker IClassifierBroker

The GPT/AI classifier broker for product categorization and allergen detection.

receiptRecognizerBroker IFormRecognizerBroker

The OCR broker for extracting invoice data from images.

loggerFactory Microsoft.Extensions.Logging.ILoggerFactory

The logger factory for creating scoped loggers.

Methods

InvoiceAnalysisFoundationService.AnalyzeInvoiceAsync(AnalysisOptions, Invoice) Method

Performs domain-level analysis / enrichment on a single invoice instance.

public System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Invoice> AnalyzeInvoiceAsync(arolariu.Backend.Domain.Invoices.DTOs.AnalysisOptions options, arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Invoice invoice);

Parameters

options AnalysisOptions

Analysis directives (which enrichment / inference steps to apply).

invoice Invoice

Target invoice aggregate to analyze (MUST NOT be null; MUST satisfy basic invariants).

Implements AnalyzeInvoiceAsync(AnalysisOptions, Invoice)

Returns

System.Threading.Tasks.Task<Invoice>
Task producing the analyzed Invoice (never null if successful).

Exceptions

System.ArgumentNullException
Thrown when invoice or options is null.

System.InvalidOperationException
Thrown when invoice state violates required preconditions for analysis.

Remarks

Behavior: Applies classification, summarization, tagging or normalization steps indicated by options and returns a new (or mutated, depending on implementation) enriched Invoice instance.

Validation: Implementations SHOULD validate option flags and invoice structural integrity (e.g., non-null collections, monetary value ranges).

Side Effects: None outside the returned object graph. No persistence, caching, or network calls (if external AI / OCR calls are required they belong in a broker invoked by an orchestration / processing layer).

Interfaces

IInvoiceAnalysisFoundationService Interface

Contract for core (foundation layer) invoice analysis operations (pure domain enrichment without orchestration side-effects).

public interface IInvoiceAnalysisFoundationService

Derived
InvoiceAnalysisFoundationService

Remarks

Role in Architecture: This foundation service applies deterministic / idempotent domain transformations to an Invoice based on supplied AnalysisOptions. It MUST NOT:

  • Trigger external side-effects (persistence, messaging, notifications).
  • Perform cross-aggregate coordination or multi-entity transactions.
  • Contain retry / resilience logic for remote dependencies (handled in higher layers).

The Standard Alignment: Foundation services encapsulate direct domain logic and validation. They throw domain or validation exceptions that are wrapped by orchestration / processing layers into higher-order classification exceptions.

Thread-Safety: Implementations SHOULD be stateless or treat internal state as immutable to allow concurrent usage.

Idempotency: For identical input invoice + options, the output SHOULD be semantically identical (pure function expectation).

Methods

IInvoiceAnalysisFoundationService.AnalyzeInvoiceAsync(AnalysisOptions, Invoice) Method

Performs domain-level analysis / enrichment on a single invoice instance.

System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Invoice> AnalyzeInvoiceAsync(arolariu.Backend.Domain.Invoices.DTOs.AnalysisOptions options, arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Invoice invoice);

Parameters

options AnalysisOptions

Analysis directives (which enrichment / inference steps to apply).

invoice Invoice

Target invoice aggregate to analyze (MUST NOT be null; MUST satisfy basic invariants).

Returns

System.Threading.Tasks.Task<Invoice>
Task producing the analyzed Invoice (never null if successful).

Exceptions

System.ArgumentNullException
Thrown when invoice or options is null.

System.InvalidOperationException
Thrown when invoice state violates required preconditions for analysis.

Remarks

Behavior: Applies classification, summarization, tagging or normalization steps indicated by options and returns a new (or mutated, depending on implementation) enriched Invoice instance.

Validation: Implementations SHOULD validate option flags and invoice structural integrity (e.g., non-null collections, monetary value ranges).

Side Effects: None outside the returned object graph. No persistence, caching, or network calls (if external AI / OCR calls are required they belong in a broker invoked by an orchestration / processing layer).

// was this page useful?