AsNet.Shared.Data 2.3.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package AsNet.Shared.Data --version 2.3.2
                    
NuGet\Install-Package AsNet.Shared.Data -Version 2.3.2
                    
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="AsNet.Shared.Data" Version="2.3.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AsNet.Shared.Data" Version="2.3.2" />
                    
Directory.Packages.props
<PackageReference Include="AsNet.Shared.Data" />
                    
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 AsNet.Shared.Data --version 2.3.2
                    
#r "nuget: AsNet.Shared.Data, 2.3.2"
                    
#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 AsNet.Shared.Data@2.3.2
                    
#: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=AsNet.Shared.Data&version=2.3.2
                    
Install as a Cake Addin
#tool nuget:?package=AsNet.Shared.Data&version=2.3.2
                    
Install as a Cake Tool

AsNet.Shared.Data

Enterprise‑grade, multi‑tenant data infrastructure library for .NET that provides dynamic connection string resolution, secure integration with AsNetSecurity and IdentityServer, and a complete generic data access framework built on Entity Framework Core.


Overview

AsNet.Shared.Data is a shared data infrastructure framework designed for enterprise and multi‑tenant applications.
It centralizes connection string resolution, security‑aware data access, and provides generic, reusable data access components for both Entity‑first and DTO‑first architectures.

The library integrates directly with AsNetSecurity (V1 and V2) and OAuth2 / OpenID Connect providers to securely resolve tenant-specific connection strings and initialize safe, isolated DbContext instances per tenant.

Authentication is delegated to AsNet.Shared.Http token services, enabling integration with multiple authorization servers including Duende IdentityServer, IdentityServer4, Microsoft Entra ID (Azure AD), Keycloak, Auth0 and custom OAuth2 providers.


Key Features

  • Multi‑tenant architecture with dynamic connection string resolution.
  • ✅ Integration with AsNetSecurity V1 / V2.
  • ✅ Secure access using OAuth2 / OpenID Connect Provider.
  • ✅ Centralized tenant initialization via BaseApplication.
  • ✅ Generic Entity‑first repositories (queries & commands).
  • ✅ Generic DTO‑first repositories using AutoMapper.
  • ✅ Support for streaming queries with IAsyncEnumerable<T>.
  • ✅ Rich stored procedure support (OUTPUT & RETURN values).
  • ✅ Transaction management.
  • ✅ Standardized result contracts (DmlResult, BResult).
  • ✅ Built‑in auditing support.
  • ✅ Contextual logging by Tenant, Entity, DTO, and Host.
  • ✅ Configuration‑driven behavior via appsettings.json.
  • ✅ Multi‑framework support.

Supported Frameworks

  • .NET Standard 2.1
  • .NET 8.0
  • .NET 9.0
  • .NET 10.0

Architecture Overview

The package is structured in three clear layers:

1️⃣ Infrastructure Layer

  • Dynamic tenant connection resolution
  • Security integration
  • DbContext initialization

Core components:

  • ApplicationSettings
  • ConnectionStringService
  • SecuritySourceEnum
  • BaseApplication<TDbContext>

2️⃣ Persistence Layer (Entity‑First)

Generic repositories built directly on Entity Framework Core.

Queries
  • GenericQueries<TEntity, TContext>

Supports:

  • Filters, ordering, includes
  • Projections
  • Streaming queries
  • Raw SQL & stored procedures
  • StandardList builders
Commands
  • GenericCommands<TEntity, TContext>
  • GenericCommandsDml<TEntity, TContext>

Supports:

  • CRUD & bulk operations
  • Transactions
  • Stored procedures
  • Typed primary key retrieval
  • DmlResult standardized responses

3️⃣ Application Layer (DTO‑First)

Designed for Application Services and APIs.

Queries
  • GenericQueriesB<TDto, TEntity, TContext>
  • GenericQueriesBResult<TDto, TEntity, TContext>

Features:

  • DTO‑first querying
  • Expression mapping (AutoMapper)
  • Streaming
  • BResult standardized responses
Commands
  • GenericCommandsB<TDto, TEntity, TContext>
  • GenericCommandsBResult<TDto, TEntity, TContext>

Features:

  • DTO‑first commands
  • Validation & existence checks
  • Optional auditing (IAuditable<TAudit>)
  • Transaction support
  • BResult for API‑friendly responses

Security & Multi‑Tenant Support

Supported Connection Sources

Connection strings can be resolved from:

  • AppSettings
  • AsNetSecurity V1
  • AsNetSecurity V2

Selection is controlled via SecuritySourceEnum and configuration defaults.

OAuth Authentication

When using AsNetSecurity V2, access tokens are obtained through the AsNet.Shared.Http token infrastructure.

Supported OAuth grant types include:

  • Client Credentials
  • Authorization Code
  • Password
  • On-Behalf-Of (OBO)
  • Token Exchange

Authentication providers can be configured using:

  • Default provider configuration
  • Named providers
  • Runtime provider settings

This allows a single application or integration service to securely communicate with multiple protected APIs and authorization servers.


Required Configuration

OAuth Provider Configuration

{
  "AsNet": {
    "Security": {

      "IdentityServerSettings": {

        "Default": {
          "Address": "https://sso.company.com",
          "ClientId": "default-client",
          "ClientSecret": "default-secret",
          "Scope": "api"
        },

        "Providers": {

          "AsNet": {
            "Address": "https://sso.company.com",
            "ClientId": "security-api-client",
            "ClientSecret": "secret",
            "Scope": "security-api"
          },

          "CustomerA": {
            "Address": "https://auth.customera.com",
            "ClientId": "customer-client",
            "ClientSecret": "customer-secret",
            "Scope": "documents"
          }
        }
      }
    }
  }
}

### ConnectionStringService Authentication

When ConnectionSource is configured as AsNetSecurityV2, the
ConnectionStringService automatically retrieves an OAuth access token using
the configured token provider.

Example:

```csharp
await tokenService.GetAccessTokenAsync(
    new TokenRequestContext
    {
        GrantType = TokenGrantType.ClientCredentials,
        ProviderName = "AsNet"
    });

The resulting token is used to securely communicate with the configured SecurityWebApi endpoint and resolve tenant-specific connection strings.

Access tokens are automatically cached by the token provider infrastructure, reducing authentication overhead and improving performance.


---

### Multi-Provider Scenario

A single application can simultaneously consume:

- AsNetSecurity APIs
- Customer APIs
- Third-party secured services

using independent OAuth provider configurations.

Example:

```csharp
// Internal AsNet Security API

var token1 = await tokenService.GetAccessTokenAsync(
    new TokenRequestContext
    {
        GrantType = TokenGrantType.ClientCredentials,
        ProviderName = "AsNet"
    });

// Customer API

var token2 = await tokenService.GetAccessTokenAsync(
    new TokenRequestContext
    {
        GrantType = TokenGrantType.ClientCredentials,
        ProviderName = "CustomerA"
    });

Each provider maintains independent OAuth configuration and token cache entries, allowing secure communication with multiple protected APIs from the same application, background service, Web API or microservice.


---
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 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 is compatible.  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
2.3.2.2 101 9/11/2026
2.3.2.1 228 7/9/2026
2.3.2 121 7/6/2026
2.3.1 248 5/26/2026
2.3.0.4 144 5/6/2026
2.3.0.3 142 5/4/2026
2.3.0.2 135 4/27/2026
2.3.0.1 195 4/8/2026
2.3.0 150 4/6/2026
2.2.2 149 3/26/2026
2.2.1.1 169 2/9/2026
2.2.1 182 1/14/2026
2.2.0 166 1/13/2026
2.1.1.6 293 6/30/2025
2.1.1.5 271 1/6/2025
2.1.1.4 244 12/9/2024
2.1.1.3 259 12/9/2024 2.1.1.3 is deprecated because it has critical bugs.
2.1.1.2 275 11/11/2024
2.1.1.1 285 9/6/2024
2.1.1 281 6/9/2024
Loading failed

• Designed for .NET 8.0, .NET 9.0, and .NET 10.0.
• Introduces a complete multi‑tenant data infrastructure built on Entity Framework Core.
• Adds dynamic connection string resolution per tenant with AsNetSecurity V1 and V2 integration.
• Includes generic Entity‑first repositories for queries and commands.
• Adds DTO‑first repositories using AutoMapper for application and API layers.
• Supports streaming data access using IAsyncEnumerable<T>.
• Includes standardized result contracts (DmlResult and BResult).
• Adds built‑in support for stored procedures with OUTPUT and RETURN values.
• Provides transaction management and optional auditing support.
• Improves contextual logging with tenant, entity, DTO, and host metadata.