FractalDataWorks.Services.Connections.MsSql 0.4.0-preview.6

This is a prerelease version of FractalDataWorks.Services.Connections.MsSql.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package FractalDataWorks.Services.Connections.MsSql --version 0.4.0-preview.6
                    
NuGet\Install-Package FractalDataWorks.Services.Connections.MsSql -Version 0.4.0-preview.6
                    
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="FractalDataWorks.Services.Connections.MsSql" Version="0.4.0-preview.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FractalDataWorks.Services.Connections.MsSql" Version="0.4.0-preview.6" />
                    
Directory.Packages.props
<PackageReference Include="FractalDataWorks.Services.Connections.MsSql" />
                    
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 FractalDataWorks.Services.Connections.MsSql --version 0.4.0-preview.6
                    
#r "nuget: FractalDataWorks.Services.Connections.MsSql, 0.4.0-preview.6"
                    
#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 FractalDataWorks.Services.Connections.MsSql@0.4.0-preview.6
                    
#: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=FractalDataWorks.Services.Connections.MsSql&version=0.4.0-preview.6&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=FractalDataWorks.Services.Connections.MsSql&version=0.4.0-preview.6&prerelease
                    
Install as a Cake Tool

FractalDataWorks.Services.Connections.MsSql

SQL Server connection implementation for the FractalDataWorks framework.

Overview

This package provides a SQL Server connection implementation using the Authentication Processor Pattern. The factory creates SqlConnection objects directly, passes them to MsSqlConnection, and the connection string goes out of scope immediately for security.

Target Framework: net10.0

Key Components

MsSqlConnection

SQL Server data connection that inherits from ConnectionBase which handles IDataCommand to SqlCommand translation.

public sealed class MsSqlConnection : ConnectionBase<SqlCommand, MsSqlConnectionConfiguration, MsSqlConnection>
{
    private readonly SqlConnection _sqlConnection;
    private readonly ILogger<MsSqlConnection> _logger;

    public MsSqlConnection(
        ILogger<MsSqlConnection> logger,
        MsSqlConnectionConfiguration configuration,
        SqlConnection sqlConnection)
        : base(logger, configuration)
    {
        _sqlConnection = sqlConnection;
        _logger = logger;
    }
}

Key Points:

  • Takes MsSqlConnectionConfiguration for metadata (Server, Database, timeouts, etc.)
  • Takes SqlConnection created by the factory - the connection string is NOT stored
  • The factory creates SqlConnection with the connection string, then the string goes out of scope

MsSqlConnectionFactory

Factory for creating SQL Server connection instances. The factory:

  1. Gets the appropriate authentication processor
  2. Builds the connection string using the processor
  3. Creates SqlConnection with that string (string goes out of scope)
  4. Creates MsSqlConnection with the configuration and SqlConnection
public sealed class MsSqlConnectionFactory : IMsSqlConnectionFactory
{
    // Bootstrap-friendly overload - accepts ISecretManager directly
    public async Task<IGenericResult<IGenericConnection>> Create(
        MsSqlConnectionConfiguration configuration,
        ISecretManager? secretManager,
        ILoggerFactory loggerFactory,
        CancellationToken cancellationToken = default)
    {
        // Resolve password from secret manager if needed
        string? resolvedPassword = null;
        if (!string.IsNullOrEmpty(configuration.Authentication?.SecretKeyName))
        {
            // Get password from secret manager...
        }

        // Build connection string using processor
        var connectionStringResult = BuildConnectionString(configuration, resolvedPassword);

        // Create SqlConnection - connection string goes out of scope after this
        var sqlConnection = new SqlConnection(connectionStringResult.Value);

        // Create the connection instance
        var connection = new MsSqlConnection(connectionLogger, configuration, sqlConnection);

        return GenericResult<IGenericConnection>.Success(connection);
    }
}

Authentication Processors

Connection string building is delegated to authentication processors (TypeCollection pattern):

// Get processor for auth type
var processor = MsSqlAuthenticationProcessors.ByName(authTypeName);

// Processor builds the connection string
var connectionString = processor.Process(builder, context);

Supported authentication types:

  • SqlAuth / SQL - SQL Server authentication (username/password from SecretManager)
  • WindowsAuth / Windows / Integrated - Windows Integrated Authentication
  • AzureAD / AAD - Azure Active Directory authentication
  • ManagedIdentity / MSI - Azure Managed Identity

MsSqlConnectionConfiguration

Configuration class with [ManagedConfiguration] attribute for database-driven configuration.

[ManagedConfiguration(
    Schema = "cfg",
    TableName = "MsSqlConnection",
    Parent = nameof(ConnectionConfigurationBase<MsSqlConnectionConfiguration>),
    ServiceCategory = "Connection",
    ServiceType = "MsSql")]
public partial class MsSqlConnectionConfiguration : ConnectionConfigurationBase<MsSqlConnectionConfiguration>
{
    public string Server { get; set; } = "localhost";
    public string Database { get; set; } = string.Empty;
    public int Port { get; set; } = 1433;
    public MsSqlAuthenticationSettings Authentication { get; set; } = new();
    // ... other properties
}

MsSqlConnectionType

ServiceTypeOption that registers with ConnectionTypes:

[ServiceTypeOption(typeof(ConnectionTypes), "MsSql")]
public sealed class MsSqlConnectionType : ConnectionTypeBase<IGenericConnection, IMsSqlConnectionFactory, MsSqlConnectionConfiguration>
{
    public MsSqlConnectionType() : base(
        name: "MsSql",
        sectionName: "MsSql",
        displayName: "SQL Server",
        description: "Microsoft SQL Server database connection",
        category: "Database")
    {
    }
}

Bootstrap Usage

For bootstrap scenarios (creating ConfigurationDb connection before DI is available):

// Create factories directly
var loggerFactory = LoggerFactory.Create(b => b.AddConsole());
var secretManagerFactory = new EnvironmentVariableSecretManagerFactory(
    loggerFactory.CreateLogger<EnvironmentVariableSecretManagerFactory>());

// Create secret manager
var secretManagerResult = await secretManagerFactory.Create(new EnvironmentVariableConfiguration());
var secretManager = secretManagerResult.Value;

// Create connection factory
var connectionFactory = new MsSqlConnectionFactory(
    loggerFactory.CreateLogger<MsSqlConnectionFactory>(),
    loggerFactory.CreateLogger<MsSqlConnection>());

// Load config from appsettings
var configDbConfig = configuration.GetSection("ConfigurationDb").Get<MsSqlConnectionConfiguration>();

// Create connection - factory accepts ISecretManager directly
var connectionResult = await connectionFactory.Create(configDbConfig, secretManager, loggerFactory);

Three-Phase Registration

After bootstrap, use three-phase registration:

// Phase 1a: Configure (bind IOptions)
ConnectionTypes.Configure(services, configuration, loggerFactory);

// Phase 1b: Register (register factories)
ConnectionTypes.Register(services, loggerFactory);

var app = builder.Build();

// Phase 2: Initialize (eager resolve, fail-fast)
ConnectionTypes.Initialize(app.Services, loggerFactory);

Cross-Assembly Registration

Since MsSqlConnectionType is in a separate NuGet package, it uses module initializers for automatic registration:

// Generated in your application assembly
[ModuleInitializer]
internal static void RegisterServiceTypeOptions()
{
    ConnectionTypes.RegisterMember(new MsSqlConnectionType());
}

This runs before Main(), ensuring MsSql is registered before ConnectionTypes.Configure() is called.

Configuration Tables

Configuration is loaded from two database tables:

Table Purpose
cfg.Connection Base connection properties (Name, Type, IsEnabled, etc.)
cfg.MsSqlConnection SQL Server-specific properties (Server, Database, Port, Auth, etc.)

Dependencies

Project References

  • FractalDataWorks.Data.MsSql - SQL Server translators
  • FractalDataWorks.Services.Connections - Connection base classes
  • FractalDataWorks.Services.SecretManagers - Secret management

Package References

  • Microsoft.Data.SqlClient - SQL Server connectivity
  • Microsoft.Extensions.DependencyInjection.Abstractions
  • Microsoft.Extensions.Logging.Abstractions
Product Compatible and additional computed target framework versions.
.NET 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 (1)

Showing the top 1 NuGet packages that depend on FractalDataWorks.Services.Connections.MsSql:

Package Downloads
FractalDataWorks.Configuration.MsSql

Development tools and utilities for the FractalDataWorks ecosystem. Build:

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
Loading failed