ClearDataService 3.0.0

dotnet add package ClearDataService --version 3.0.0
                    
NuGet\Install-Package ClearDataService -Version 3.0.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="ClearDataService" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ClearDataService" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ClearDataService" />
                    
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 ClearDataService --version 3.0.0
                    
#r "nuget: ClearDataService, 3.0.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 ClearDataService@3.0.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=ClearDataService&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ClearDataService&version=3.0.0
                    
Install as a Cake Tool

ClearDataService

NuGet version License: MIT .NET

A comprehensive data access library for .NET 9 that combines the power of Entity Framework Core with the flexibility of Dapper for SQL Server operations, plus complete Azure Cosmos DB support. ClearDataService provides a unified approach to data operations across both relational and NoSQL databases.

? Features

??? Dual Database Support

  • SQL Server: Entity Framework Core + Dapper integration for maximum flexibility
  • Azure Cosmos DB: Complete document database operations with partition key support
  • Unified Patterns: Consistent repository pattern across both database types

??? Architecture Excellence

  • Clean Architecture: Well-defined abstractions and separation of concerns
  • Dependency Injection: Full .NET Core DI container integration
  • Repository Pattern: Built-in repository implementations for both database types
  • Entity Framework Integration: Leverage EF Core's ORM capabilities
  • Raw SQL Support: Execute custom SQL queries using Dapper

?? Entity Management

  • Base Entity Classes: Pre-built entities with audit trail support
  • Flexible Querying: LINQ support for both SQL and Cosmos DB
  • Batch Operations: Efficient bulk operations for performance
  • Soft Delete: Built-in soft delete functionality
  • Audit Trails: Automatic creation and modification tracking

?? Developer Experience

  • Migration Support: Automated database and container creation
  • Configuration Management: Multiple configuration options
  • Exception Handling: Comprehensive error handling with custom exceptions
  • Extensive Documentation: Complete guides and examples
  • Testing Support: Built-in testing utilities and mocks

?? Quick Start

Installation

dotnet add package ClearDataService --version 3.0.0

SQL Database Setup

// Program.cs
using ClearDataService;

// Register Entity Framework DbContext
builder.Services.AddDbContext<MyDbContext>(options =>
    options.UseSqlServer(connectionString));

// Register ClearDataService SQL context
builder.Services.AddSqlDbContext();

// Optional: Auto-migrate database
app.MigrateSqlDatabase();

Cosmos DB Setup

// Using settings object
var cosmosSettings = CosmosDbSettings.Create(
    endpointUri: "https://your-account.documents.azure.com:443/",
    primaryKey: "your-primary-key",
    databaseName: "your-database-name"
);

builder.Services.AddCosmosDbContext(cosmosSettings);

// Create database and containers
app.CreateCosmosDatabaseAndContainers(
    new CosmosDbContainerInfo("Users", "/partitionKey"),
    new CosmosDbContainerInfo("Orders", "/customerId")
);

?? Usage Examples

SQL Repository Example

public class User : BaseSqlDbEntity<int>
{
    public required string Name { get; set; }
    public required string Email { get; set; }
    public bool IsActive { get; set; } = true;
}

public interface IUserRepository : ISqlDbRepo<User>
{
    Task<User?> GetByEmailAsync(string email);
    Task<List<User>> GetActiveUsersAsync();
}

public class UserRepository : BaseSqlDbRepo<User>, IUserRepository
{
    public UserRepository(ISqlDbContext context) : base(context) { }

    public async Task<User?> GetByEmailAsync(string email)
        => await Get(u => u.Email == email);

    public async Task<List<User>> GetActiveUsersAsync()
        => await Find(u => u.IsActive);
}

Cosmos DB Repository Example

public class Order : BaseCosmosDbEntity
{
    public required string CustomerId { get; set; }
    public required List<OrderItem> Items { get; set; }
    public decimal TotalAmount { get; set; }
    public OrderStatus Status { get; set; }
}

public class OrderRepository : BaseCosmosDbRepo<Order>
{
    public OrderRepository(ICosmosDbContext context) : base(context, "Orders") { }

    public async Task<List<Order>> GetByCustomerAsync(string customerId)
        => await Get(customerId); // customerId is the partition key

    public async Task<Order> CreateOrderAsync(Order order, string customerId)
        => await Create(order, customerId);
}

Service Integration

public class ECommerceService
{
    private readonly IUserRepository _userRepository;     // SQL
    private readonly IOrderRepository _orderRepository;   // Cosmos DB

    public ECommerceService(IUserRepository userRepository, IOrderRepository orderRepository)
    {
        _userRepository = userRepository;
        _orderRepository = orderRepository;
    }

    public async Task<Order> ProcessOrderAsync(string customerId, List<OrderItem> items)
    {
        // Validate user exists in SQL database
        var user = await _userRepository.Get(int.Parse(customerId));
        if (user == null) throw new ArgumentException("User not found");

        // Create order in Cosmos DB
        var order = new Order
        {
            Id = Guid.NewGuid().ToString(),
            CustomerId = customerId,
            Items = items,
            TotalAmount = items.Sum(i => i.TotalPrice),
            Status = OrderStatus.Pending
        };

        return await _orderRepository.CreateOrderAsync(order, customerId);
    }
}

?? Configuration

SQL Database Configuration

// Basic setup
builder.Services.AddDbContext<MyDbContext>(options =>
    options.UseSqlServer(connectionString));
builder.Services.AddSqlDbContext();

// With auto-migration
app.MigrateSqlDatabase();

Cosmos DB Configuration

// Using configuration file
// appsettings.json
{
  "CosmosDb": {
    "EndpointUri": "https://your-account.documents.azure.com:443/",
    "PrimaryKey": "your-primary-key",
    "DatabaseName": "your-database-name"
  }
}

// Register service
builder.Services.AddCosmosDbContext(configuration, "CosmosDb");

?? Documentation

For comprehensive documentation, examples, and advanced usage patterns, see:

??? Architecture

???????????????????????????????????????
?           Application Layer         ?
???????????????????????????????????????
?         Repository Layer            ?
?  ????????????????????????????????????
?  ? SQL Repositories?Cosmos Repos   ??
?  ????????????????????????????????????
???????????????????????????????????????
?           Context Layer             ?
?  ????????????????????????????????????
?  ?   SqlDbContext  ?CosmosDbContext??
?  ????????????????????????????????????
???????????????????????????????????????
?          Data Access Layer          ?
?  ????????????????????????????????????
?  ? EF Core/Dapper  ? Cosmos Client ??
?  ????????????????????????????????????
???????????????????????????????????????

?? Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

?? License

This project is licensed under the MIT License - see the LICENSE file for details.

?? Acknowledgments

?? Support


Made with ?? by Clearwox Systems

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 121 8/9/2025
3.0.0-preview9 111 6/20/2025
3.0.0-preview8 289 6/10/2025
3.0.0-preview6 190 5/5/2025
3.0.0-preview5 143 4/29/2025
3.0.0-preview4 176 4/24/2025
3.0.0-preview2 195 4/14/2025
3.0.0-preview10 217 6/30/2025
3.0.0-preview1 199 4/14/2025
2.0.1 144 1/31/2025
2.0.0 96 1/17/2025
1.0.4 155 10/1/2024
1.0.3 129 9/7/2024
1.0.2 160 4/6/2024