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
<PackageReference Include="ApiFeatures.Authentications.Sessions.Postgresqls" Version="9.0.0" />
<PackageVersion Include="ApiFeatures.Authentications.Sessions.Postgresqls" Version="9.0.0" />
<PackageReference Include="ApiFeatures.Authentications.Sessions.Postgresqls" />
paket add ApiFeatures.Authentications.Sessions.Postgresqls --version 9.0.0
#r "nuget: ApiFeatures.Authentications.Sessions.Postgresqls, 9.0.0"
#:package ApiFeatures.Authentications.Sessions.Postgresqls@9.0.0
#addin nuget:?package=ApiFeatures.Authentications.Sessions.Postgresqls&version=9.0.0
#tool nuget:?package=ApiFeatures.Authentications.Sessions.Postgresqls&version=9.0.0
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
ISessionServiceusing 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 implementationPostgresSessionDatabaseContext- Entity Framework Core DbContextPostgresSessionAuthenticationDatabaseOptions- 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:
- Install this package:
dotnet add package ApiFeatures.Authentications.Sessions.Postgresqls - Add using statement:
using ApiFeatures.Authentications.Sessions.Postgresqls.Extensions; - Replace
.WithDatabase(postgresOptions)with.WithPostgresDatabase(postgresOptions) - 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 | Versions 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. |
-
net9.0
- ApiFeatures.Authentications.Sessions (>= 9.0.0)
- BusinessFeatures.Cores (>= 9.0.1)
- Microsoft.EntityFrameworkCore (>= 9.0.0)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 9.0.2)
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 |