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.

Fields

InvoiceAnalysisFoundationService.analysisBroker Field

private readonly IClassifierBroker analysisBroker;

Field Value

IClassifierBroker

InvoiceAnalysisFoundationService.logger Field

private readonly ILogger<IInvoiceAnalysisFoundationService> logger;

Field Value

Microsoft.Extensions.Logging.ILogger<IInvoiceAnalysisFoundationService>

InvoiceAnalysisFoundationService.receiptRecognizerBroker Field

private readonly IFormRecognizerBroker receiptRecognizerBroker;

Field Value

IFormRecognizerBroker

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).

InvoiceAnalysisFoundationService.Classify(Exception) Method

private System.Exception Classify(System.Exception exception);

Parameters

exception System.Exception

Returns

System.Exception

InvoiceAnalysisFoundationService.LogAndWrapDependency(Exception) Method

private arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Exceptions.Outer.Foundation.InvoiceFoundationDependencyException LogAndWrapDependency(System.Exception exception);

Parameters

exception System.Exception

Returns

InvoiceFoundationDependencyException

InvoiceAnalysisFoundationService.LogAndWrapDependencyValidation(Exception) Method

private arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Exceptions.Outer.Foundation.InvoiceFoundationDependencyValidationException LogAndWrapDependencyValidation(System.Exception exception);

Parameters

exception System.Exception

Returns

InvoiceFoundationDependencyValidationException

InvoiceAnalysisFoundationService.LogAndWrapService(Exception) Method

private arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Exceptions.Outer.Foundation.InvoiceFoundationServiceException LogAndWrapService(System.Exception exception);

Parameters

exception System.Exception

Returns

InvoiceFoundationServiceException

InvoiceAnalysisFoundationService.LogAndWrapValidation(Exception) Method

private arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Exceptions.Outer.Foundation.InvoiceFoundationValidationException LogAndWrapValidation(System.Exception exception);

Parameters

exception System.Exception

Returns

InvoiceFoundationValidationException

InvoiceAnalysisFoundationService.PerformGptAnalysis(Invoice, AnalysisOptions) Method

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

Parameters

invoice Invoice

options AnalysisOptions

Returns

System.Threading.Tasks.Task<Invoice>

InvoiceAnalysisFoundationService.PerformOcrAnalysis(Invoice, AnalysisOptions) Method

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

Parameters

invoice Invoice

options AnalysisOptions

Returns

System.Threading.Tasks.Task<Invoice>

InvoiceAnalysisFoundationService.TryCatchAsync(ReturningAnalysisFunction) Method

private System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Invoice> TryCatchAsync(arolariu.Backend.Domain.Invoices.Services.Foundation.InvoiceAnalysis.InvoiceAnalysisFoundationService.ReturningAnalysisFunction returningAnalysisFunction);

Parameters

returningAnalysisFunction ReturningAnalysisFunction()

Returns

System.Threading.Tasks.Task<Invoice>

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).

Delegates

InvoiceAnalysisFoundationService.ReturningAnalysisFunction() Delegate

private delegate System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Invoice> InvoiceAnalysisFoundationService.ReturningAnalysisFunction();

Returns

System.Threading.Tasks.Task<Invoice>

// was this page useful?