FractalDataWorks.Services.Connections.MsSql
0.4.0-preview.6
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
<PackageReference Include="FractalDataWorks.Services.Connections.MsSql" Version="0.4.0-preview.6" />
<PackageVersion Include="FractalDataWorks.Services.Connections.MsSql" Version="0.4.0-preview.6" />
<PackageReference Include="FractalDataWorks.Services.Connections.MsSql" />
paket add FractalDataWorks.Services.Connections.MsSql --version 0.4.0-preview.6
#r "nuget: FractalDataWorks.Services.Connections.MsSql, 0.4.0-preview.6"
#:package FractalDataWorks.Services.Connections.MsSql@0.4.0-preview.6
#addin nuget:?package=FractalDataWorks.Services.Connections.MsSql&version=0.4.0-preview.6&prerelease
#tool nuget:?package=FractalDataWorks.Services.Connections.MsSql&version=0.4.0-preview.6&prerelease
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
MsSqlConnectionConfigurationfor metadata (Server, Database, timeouts, etc.) - Takes
SqlConnectioncreated by the factory - the connection string is NOT stored - The factory creates
SqlConnectionwith the connection string, then the string goes out of scope
MsSqlConnectionFactory
Factory for creating SQL Server connection instances. The factory:
- Gets the appropriate authentication processor
- Builds the connection string using the processor
- Creates
SqlConnectionwith that string (string goes out of scope) - Creates
MsSqlConnectionwith 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 AuthenticationAzureAD/AAD- Azure Active Directory authenticationManagedIdentity/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 translatorsFractalDataWorks.Services.Connections- Connection base classesFractalDataWorks.Services.SecretManagers- Secret management
Package References
Microsoft.Data.SqlClient- SQL Server connectivityMicrosoft.Extensions.DependencyInjection.AbstractionsMicrosoft.Extensions.Logging.Abstractions
Related Packages
- FractalDataWorks.Services.Connections - Connection base classes
- FractalDataWorks.Services.Connections.Abstractions - Interfaces
- FractalDataWorks.Data.MsSql - SQL Server translators
| Product | Versions 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. |
-
net10.0
- FractalDataWorks.Commands.Data.Abstractions (>= 0.4.0-preview.6)
- FractalDataWorks.Configuration.Abstractions (>= 0.4.0-preview.6)
- FractalDataWorks.Data (>= 0.4.0-preview.6)
- FractalDataWorks.Data.Abstractions (>= 0.4.0-preview.6)
- FractalDataWorks.Data.DataStores.Abstractions (>= 0.4.0-preview.6)
- FractalDataWorks.Data.MsSql (>= 0.4.0-preview.6)
- FractalDataWorks.MessageLogging.Abstractions (>= 0.4.0-preview.6)
- FractalDataWorks.Messages (>= 0.4.0-preview.6)
- FractalDataWorks.Results (>= 0.4.0-preview.6)
- FractalDataWorks.Results.Abstractions (>= 0.4.0-preview.6)
- FractalDataWorks.Services (>= 0.4.0-preview.6)
- FractalDataWorks.Services.Connections (>= 0.4.0-preview.6)
- FractalDataWorks.Services.Connections.Abstractions (>= 0.4.0-preview.6)
- FractalDataWorks.Services.Data.Abstractions (>= 0.4.0-preview.6)
- FractalDataWorks.Services.SecretManagers (>= 0.4.0-preview.6)
- Microsoft.Data.SqlClient (>= 7.0.0-preview2.25289.6)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.1)
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 |
|---|