TAF.Infra.Contract
1.10.11
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package TAF.Infra.Contract --version 1.10.11
NuGet\Install-Package TAF.Infra.Contract -Version 1.10.11
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="TAF.Infra.Contract" Version="1.10.11" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TAF.Infra.Contract" Version="1.10.11" />
<PackageReference Include="TAF.Infra.Contract" />
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 TAF.Infra.Contract --version 1.10.11
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TAF.Infra.Contract, 1.10.11"
#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 TAF.Infra.Contract@1.10.11
#: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=TAF.Infra.Contract&version=1.10.11
#tool nuget:?package=TAF.Infra.Contract&version=1.10.11
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
TAF.Infra.Contract
A comprehensive contract library that provides common models, interfaces, and data structures for the TAF Infrastructure ecosystem. This package contains shared DTOs, enums, base classes, and contract definitions that ensure consistency across all TAF microservices and applications.
๐ Features
- Shared Data Models: Common DTOs and data structures for inter-service communication
- Interface Contracts: Standardized interfaces for consistent service implementation
- Base Classes: Foundational classes for common patterns across services
- Enum Definitions: Standardized enumeration values for consistent data representation
- Type Safety: Strongly-typed contracts ensuring compile-time validation
- Cross-Service Consistency: Unified contracts across the entire TAF ecosystem
๐ฆ Installation
dotnet add package TAF.Infra.Contract
๐๏ธ What's Included
Data Transfer Objects (DTOs)
- Common request/response models
- Shared data structures
- API contract definitions
Base Classes
- Base entity classes
- Common abstract classes
- Shared implementation patterns
Interfaces
- Service contract definitions
- Repository interfaces
- Common abstractions
Enumerations
- Status codes
- Type definitions
- Configuration constants
๐ Quick Start
1. Installation
Add the package to your project:
dotnet add package TAF.Infra.Contract
2. Using Common Models
using TAF.Infra.Contract.Models;
using TAF.Infra.Contract.Enums;
// Use shared DTOs
public class UserService
{
public async Task<UserDto> GetUserAsync(Guid userId)
{
// Implementation using common contract models
return new UserDto
{
Id = userId,
Status = UserStatus.Active
};
}
}
3. Implementing Common Interfaces
using TAF.Infra.Contract.Interfaces;
// Implement standardized interfaces
public class ProductRepository : IRepository<Product>
{
public async Task<Product> GetByIdAsync(Guid id)
{
// Implementation
}
public async Task<IEnumerable<Product>> GetAllAsync()
{
// Implementation
}
}
4. Using Base Classes
using TAF.Infra.Contract.Base;
// Extend from common base classes
public class Product : BaseEntity
{
public string Name { get; set; }
public decimal Price { get; set; }
// BaseEntity provides: Id, CreatedAt, UpdatedAt, etc.
}
๐ Package Structure
Models
- BaseDto: Common properties for all DTOs
- ApiResponse<T>: Standardized API response wrapper
- PaginationRequest: Common pagination parameters
- PaginationResponse<T>: Paginated response structure
Enums
- ServiceStatus: Common service status values
- OperationResult: Standard operation result codes
- EntityState: Entity lifecycle states
Interfaces
- IRepository<T>: Generic repository pattern
- IService<T>: Common service interface
- IAuditable: Auditing interface for entities
Base Classes
- BaseEntity: Common entity base class with Id, timestamps
- BaseService: Common service implementation patterns
- BaseController: Standard API controller base
๐ ๏ธ Best Practices
Model Design
// Always inherit from base classes when appropriate
public class OrderDto : BaseDto
{
public string OrderNumber { get; set; }
public OrderStatus Status { get; set; }
public List<OrderItemDto> Items { get; set; }
}
Interface Implementation
// Use common interfaces for consistency
public class OrderService : IOrderService
{
public async Task<ApiResponse<OrderDto>> CreateOrderAsync(CreateOrderRequest request)
{
// Standardized response format
return new ApiResponse<OrderDto>
{
Success = true,
Data = createdOrder,
Message = "Order created successfully"
};
}
}
Enum Usage
// Use shared enums for consistency across services
public class Order : BaseEntity
{
public OrderStatus Status { get; set; } = OrderStatus.Pending;
public PaymentStatus PaymentStatus { get; set; } = PaymentStatus.Unpaid;
}
๐ง Extending Contracts
Adding New Models
// Follow naming conventions
public class ProductDto : BaseDto
{
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public ProductCategory Category { get; set; }
}
Creating Custom Interfaces
// Extend base interfaces when needed
public interface IProductService : IService<Product>
{
Task<IEnumerable<Product>> GetByCategoryAsync(ProductCategory category);
Task<bool> UpdatePriceAsync(Guid productId, decimal newPrice);
}
๐งช Testing Support
The contract library provides:
- Mock-friendly interfaces
- Testable base classes
- Consistent data structures for unit tests
// Easy to mock standardized interfaces
var mockRepository = new Mock<IRepository<Product>>();
mockRepository.Setup(r => r.GetByIdAsync(It.IsAny<Guid>()))
.ReturnsAsync(new Product { Name = "Test Product" });
๐ Version Compatibility
This package follows semantic versioning:
- Major: Breaking changes to contracts
- Minor: New models, interfaces, or enums (backward compatible)
- Patch: Bug fixes and documentation updates
๐ค Contributing
When adding new contracts:
- Follow existing naming conventions
- Add comprehensive documentation
- Include usage examples
- Ensure backward compatibility
- Update version appropriately
๐ License
This project is licensed under the MIT License.
๐ Issues
If you encounter any issues, please file them in the GitHub Issues section.
Built with โค๏ธ for consistent microservices architecture
| Product | Versions 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. |