Foundation.Application.Contracts 1.1.0

dotnet add package Foundation.Application.Contracts --version 1.1.0
                    
NuGet\Install-Package Foundation.Application.Contracts -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Foundation.Application.Contracts" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Foundation.Application.Contracts" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Foundation.Application.Contracts" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Foundation.Application.Contracts --version 1.1.0
                    
#r "nuget: Foundation.Application.Contracts, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Foundation.Application.Contracts@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Foundation.Application.Contracts&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Foundation.Application.Contracts&version=1.1.0
                    
Install as a Cake Tool

Foundation.Application.Contracts

Application layer contracts for the Foundation framework, providing DTOs, interfaces, and CQRS contracts.

📦 Package Contents

This package provides the contracts for clean application architecture:

  • DTOs: Data Transfer Objects for API requests/responses
  • Commands: CQRS command contracts
  • Queries: CQRS query contracts
  • Service Interfaces: Application service contracts
  • Common Contracts: Shared application interfaces (IUnitOfWork, IRepository, etc.)
  • Validation Contracts: Input validation interfaces

🚀 Installation

dotnet add package Foundation.Application.Contracts

📖 Usage

DTOs (Data Transfer Objects)

Create request and response DTOs:

public record CreateProductRequest(
    string Name,
    string Description,
    decimal Price,
    int CategoryId
);

public record ProductDto(
    Guid Id,
    string Name,
    string Description,
    decimal Price,
    string CategoryName,
    DateTime CreatedAt
);

Command Contracts

Define commands for CQRS:

public record CreateProductCommand(
    string Name,
    string Description,
    decimal Price,
    int CategoryId
) : ICommand<ProductDto>;

public record UpdateProductCommand(
    Guid Id,
    string Name,
    string Description,
    decimal Price
) : ICommand;

Query Contracts

Define queries for CQRS:

public record GetProductByIdQuery(Guid Id) : IQuery<ProductDto>;

public record GetProductsQuery(
    int PageNumber = 1,
    int PageSize = 10,
    string? SearchTerm = null
) : IQuery<PagedResult<ProductDto>>;

Service Interfaces

Define application service contracts:

public interface IEmailService
{
    Task SendEmailAsync(EmailMessage message, CancellationToken cancellationToken = default);
    Task SendTemplatedEmailAsync<TModel>(
        string templateId, 
        string to, 
        TModel model, 
        CancellationToken cancellationToken = default);
}

public interface ICurrentUserService
{
    Guid UserId { get; }
    string Email { get; }
    IReadOnlyList<string> Roles { get; }
    bool IsAuthenticated { get; }
}

Repository Contracts

Define repository interfaces:

public interface IRepository<TEntity> where TEntity : BaseEntity
{
    Task<TEntity?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default);
    Task<IReadOnlyList<TEntity>> GetAllAsync(CancellationToken cancellationToken = default);
    Task<TEntity> AddAsync(TEntity entity, CancellationToken cancellationToken = default);
    Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default);
    Task DeleteAsync(TEntity entity, CancellationToken cancellationToken = default);
    Task<IReadOnlyList<TEntity>> GetBySpecificationAsync(
        ISpecification<TEntity> specification, 
        CancellationToken cancellationToken = default);
}

Common Response Types

Standard response wrappers:

public record ApiResponse<T>(
    T? Data,
    bool IsSuccess,
    string? Message,
    IReadOnlyList<string>? Errors
);

public record PagedResult<T>(
    IReadOnlyList<T> Items,
    int TotalCount,
    int PageNumber,
    int PageSize
)
{
    public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
    public bool HasPreviousPage => PageNumber > 1;
    public bool HasNextPage => PageNumber < TotalPages;
}

🏗️ Architecture

This package follows Clean Architecture principles:

  • No implementation details: Only contracts and DTOs
  • Framework agnostic: Can be used with any DI container
  • CQRS support: Clear command/query separation
  • Testable: Interfaces enable easy mocking

📋 Requirements

  • .NET 8.0 or higher
  • Foundation.Domain.Models package

🤝 Contributing

This package is part of the Foundation framework. See the main repository for contribution guidelines.

📄 License

MIT License - see LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Foundation.Application.Contracts:

Package Downloads
Foundation.Infrastructure.Common

Common infrastructure implementations for Foundation microservices including caching, logging, middleware, and resilience patterns.

Foundation.Client.SDK

Client SDK for Foundation microservices providing typed HTTP clients with built-in resilience, authentication, and service discovery.

Foundation.ServiceDiscovery

Service discovery infrastructure for Foundation microservices. Provides dynamic service resolution with multiple discovery providers (Kubernetes, Consul, Configuration), intelligent caching, health checking, and seamless integration with Foundation.Client.SDK.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 475 7/22/2025
1.0.0 472 7/22/2025