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" />
<PackageReference Include="Korjn.OracleClientInject" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=Korjn.OracleClientInject&version=9.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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
andtnsnames.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 | 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.3)
- Microsoft.Extensions.Options (>= 9.0.3)
- Microsoft.Extensions.Options.DataAnnotations (>= 9.0.3)
- Oracle.ManagedDataAccess.Core (>= 23.8.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.