ApiFeatures.Authentications.Sessions.Postgresqls 9.0.0

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

ApiFeatures.Authentications.Sessions.Postgresqls

PostgreSQL database implementation for the Session Authentication feature using Entity Framework Core.

Overview

This package provides PostgreSQL storage support for the ApiFeatures.Authentications.Sessions library. It separates PostgreSQL-specific concerns from the core session authentication functionality and uses Entity Framework Core for data access.

Installation

dotnet add package ApiFeatures.Authentications.Sessions.Postgresqls

Usage

using ApiFeatures.Authentications.Sessions.Extensions;
using ApiFeatures.Authentications.Sessions.Postgresqls.Extensions;
using ApiFeatures.Authentications.Sessions.Postgresqls.Models.Options;

var builder = WebApplication.CreateBuilder(args);

// Configure session authentication with PostgreSQL
var postgresOptions = new PostgresSessionAuthenticationDatabaseOptions
{
    ConnectionString = "Host=localhost;Database=SessionAuthDb;Username=postgres;Password=yourpassword",
    Schema = "public",
    TableName = "sessions"
};

builder.Services.AddSessionAuthenticationFeature(options => options
    .WithBusinessLogic<YourBusinessLogic>()
    .WithPostgresDatabase(postgresOptions)
    // ... other configurations
);

Database Migration

To create and apply database migrations:

# Add migration
dotnet ef migrations add InitialCreate --project src/modules/authentication/session/ApiFeatures.Authentications.Sessions.Postgresqls

# Update database
dotnet ef database update --project src/modules/authentication/session/ApiFeatures.Authentications.Sessions.Postgresqls

Features

  • PostgresSessionService: PostgreSQL implementation of ISessionService using EF Core
  • PostgresSessionDatabaseContext: Entity Framework Core DbContext with proper configuration
  • PostgresSessionAuthenticationDatabaseOptions: Configuration options for PostgreSQL connection
  • Extension Methods: Fluent API for easy configuration
  • Automatic Indexing: Optimized indexes on Key, Username, and ExpiryTime columns
  • Complex Type Mapping: Properly configured metadata storage for device and browser information

Database Schema

The package creates the following schema:

CREATE TABLE sessions (
    Id UUID PRIMARY KEY,
    Key VARCHAR(500) NOT NULL UNIQUE,
    Username VARCHAR(255) NOT NULL,
    ExpiryTime TIMESTAMP WITH TIME ZONE,
    CreatedTime TIMESTAMP WITH TIME ZONE NOT NULL,
    -- Metadata columns (Device and Browser)
    DeviceName VARCHAR(255),
    DeviceModel VARCHAR(255),
    BrowserName VARCHAR(255),
    BrowserVersion VARCHAR(255),
    BrowserLanguage VARCHAR(50)
);

-- Indexes
CREATE UNIQUE INDEX IX_Session_Key ON sessions(Key);
CREATE INDEX IX_Session_Username ON sessions(Username);
CREATE INDEX IX_Session_ExpiryTime ON sessions(ExpiryTime) WHERE ExpiryTime IS NOT NULL;

Components Moved from Core Package

This package contains the following components that were previously in ApiFeatures.Authentications.Sessions:

  • PostgresSessionService - PostgreSQL session service implementation
  • PostgresSessionDatabaseContext - Entity Framework Core DbContext
  • PostgresSessionAuthenticationDatabaseOptions - PostgreSQL configuration options

Configuration Options

PostgresSessionAuthenticationDatabaseOptions

  • ConnectionString (required): PostgreSQL connection string
  • Schema (required): Database schema name (typically "public")
  • TableName (optional): Table name for sessions (default: "sessions")
  • MigrationTable (optional): Migration history table name. If not set, EF Core uses its default "__EFMigrationsHistory" table

Example with Custom Migration Table

var postgresOptions = new PostgresSessionAuthenticationDatabaseOptions
{
    ConnectionString = "Host=localhost;Database=SessionAuthDb;Username=postgres;Password=yourpassword",
    Schema = "public",
    TableName = "sessions",
    MigrationTable = "CustomMigrationHistory" // Optional: use custom migration table
};

Dependencies

  • ApiFeatures.Authentications.Sessions
  • Microsoft.EntityFrameworkCore (9.0.0)
  • Npgsql.EntityFrameworkCore.PostgreSQL (9.0.2)
  • BusinessFeatures.Cores

Migration Guide

If you were previously using PostgreSQL with the core ApiFeatures.Authentications.Sessions package:

  1. Install this package: dotnet add package ApiFeatures.Authentications.Sessions.Postgresqls
  2. Add using statement: using ApiFeatures.Authentications.Sessions.Postgresqls.Extensions;
  3. Replace .WithDatabase(postgresOptions) with .WithPostgresDatabase(postgresOptions)
  4. Ensure the database schema is created using EF Core migrations

Performance Considerations

  • The package uses AsNoTracking() for read operations to improve performance
  • Proper indexes are automatically created on Key, Username, and ExpiryTime
  • Connection pooling is handled by Npgsql
  • Consider using a connection pool size appropriate for your workload

License

[Your License Here]

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
9.0.0 33 5/7/2026