Korjn.OracleClientInject 9.0.5

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

Korjn.OracleClientInject

๐Ÿ’ก Lightweight, testable Oracle connection factory for .NET with full DI support, secure credential handling, and built-in IOptions validation.


โœจ Features

  • โœ… Simple and consistent factory API via IOracleConnectionFactory
  • โœ… Fully supports IOptions<T> pattern with [Required] validation
  • ๐Ÿ” Lazy, secure connection string construction (no secrets in memory until needed)
  • ๐ŸŽฏ Supports both sync and async connection creation
  • ๐Ÿงช Easily mockable for testing scenarios
  • ๐Ÿ›  Integration with TNS_ADMIN and tnsnames.ora support
  • ๐ŸŒฑ Clean setup via AddOracleClient(...) extensions

๐Ÿ“ฆ Installation

Install-Package Korjn.OracleClientInject

๐Ÿš€ Quick Start

1. Register via DI

In your Program.cs:

builder.Services.AddOracleClient(options =>
{
    options.DataSource = "MyTNSAlias";
    options.UserName = "scott";
    options.Password = "tiger";
    options.DefaultSchema = "myschema";
});

Or with access to other services:

builder.Services.AddOracleClient((options, sp) =>
{
    var config = sp.GetRequiredService<IConfiguration>();
    options.DataSource = config["Db:DataSource"];
    options.UserName = config["Db:User"];
    options.Password = config["Db:Password"];
});

2. Inject and use IOracleConnectionFactory

public class MyService(IOracleConnectionFactory factory)
{
    public async Task DoSomethingAsync()
    {
        await using var conn = await factory.CreateConnectionAsync(CancellationToken.None);
        using var cmd = conn.CreateCommand();
        cmd.CommandText = "SELECT * FROM DUAL";

        using var reader = await cmd.ExecuteReaderAsync();
        while (await reader.ReadAsync())
        {
            Console.WriteLine(reader.GetString(0));
        }
    }
}

๐Ÿ›  Configuration Example (appsettings.json)

{
  "OracleDbClient": {
    "TnsnamesFile": "C:\oracle\network\admin\tnsnames.ora",
    "DataSource": "ORCL",
    "UserName": "scott",
    "Password": "tiger",
    "DefaultSchema": "HR",
    "Pooling": true,
    "MinPoolSize": 1,
    "MaxPoolSize": 100,
    "IncrPoolSize": 1,
    "DecrPoolSize": 1,
    "ConnectionLifeTime": 0,
    "ConnectionTimeout": 15
  }
}

๐Ÿงฉ API Overview

OracleConnectionOptions

Property Type Default Description
TnsnamesFile string? โ€” Path to tnsnames.ora file
DataSource string โ€” TNS alias or host:[port]/service
UserName string? โ€” Oracle DB username
Password string? โ€” Oracle DB password
DefaultSchema string? โ€” Optional schema for session (ALTER SESSION)
Pooling bool? true Enable or disable connection pooling
MinPoolSize int? 1 Minimum connections in pool
MaxPoolSize int? 100 Maximum connections in pool
IncrPoolSize int? 1 Pool increment size when exhausted
DecrPoolSize int? 1 Pool decrement size when idle
ConnectionLifeTime int? 0 Seconds until pooled connection is destroyed
ConnectionTimeout int? 15 Seconds to wait before connection times out

๐Ÿ”ง Interface: IOracleConnectionFactory

public interface IOracleConnectionFactory
{
    OracleConnectionOptions ConnectionOptions { get; }
    string ConnectionStringAttributes { get; }
    string ConnectionString { get; }

    OracleConnection CreateConnection();
    OracleConnection CreateConnection(string userName, string password);

    Task<OracleConnection> CreateConnectionAsync(CancellationToken cancellationToken);
    Task<OracleConnection> CreateConnectionAsync(string userName, string password, CancellationToken cancellationToken);
}

๐Ÿงฉ Extension Methods

public static class ServiceCollectionExtensions
{
    IServiceCollection AddOracleClient(Action<OracleConnectionOptions> configure);
    IServiceCollection AddOracleClient(Action<OracleConnectionOptions, IServiceProvider> configureOptions);
}

Both methods:

  • Register IOracleConnectionFactory as singleton
  • Validate OracleConnectionOptions on app start

๐Ÿ“œ License

MIT ยฉ Korjn

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.5 144 5/21/2025
9.0.4 148 5/8/2025
9.0.3 113 5/2/2025
9.0.2 203 4/17/2025
9.0.1 93 4/5/2025
9.0.0 122 4/4/2025