Naravel.Foundation
0.2.0
dotnet add package Naravel.Foundation --version 0.2.0
NuGet\Install-Package Naravel.Foundation -Version 0.2.0
<PackageReference Include="Naravel.Foundation" Version="0.2.0" />
<PackageVersion Include="Naravel.Foundation" Version="0.2.0" />
<PackageReference Include="Naravel.Foundation" />
paket add Naravel.Foundation --version 0.2.0
#r "nuget: Naravel.Foundation, 0.2.0"
#:package Naravel.Foundation@0.2.0
#addin nuget:?package=Naravel.Foundation&version=0.2.0
#tool nuget:?package=Naravel.Foundation&version=0.2.0
Naravel.Foundation
The shared base of Naravel's driver-based modules: named drivers built once from configuration, replaceable while the application runs, and disposed by one owner.
| Fact | Detail |
|---|---|
| Install | dotnet add package Naravel.Foundation. Applications get it with the module they use; install it yourself when you write a driver-based module of your own |
| Targets | .NET 10 |
| Needs | Microsoft.Extensions.Configuration, Microsoft.Extensions.DependencyInjection.Abstractions, Microsoft.Extensions.Options and Microsoft.Extensions.Options.ConfigurationExtensions, and no other Naravel module |
| Used by | Naravel.Cache, Naravel.Database, Naravel.Filesystem, Naravel.Mail, Naravel.Queue, Naravel.Redis and Naravel.Broadcasting |
What you get
- Named drivers.
Manager<TDriver, TOptions>returns the driver registered under a name withDriver(name), or withDriverAsync(name, cancellationToken)when its factory is asynchronous. It builds each driver once, even when callers arrive together, and caches it; a creation that fails is not cached, so the next call tries again. - A default and settings from configuration.
ManagerOptionscarriesDefault, the name thatDriver()uses, andStores, one configuration section per driver, which a factory reads withGetStore(name). A changedDefaultapplies on the next call; a changedStoresretires the cached drivers, so the next call builds new ones. - Drivers added while the application runs.
Extend(name, factory)registers a synchronous or asynchronous factory on a manager that is already built and replaces an existing name;Forget(name)andForgetAll()retire cached instances. - Registration.
AddNaravelManagerregisters the manager, its driver registry and a directTDriverservice for the default driver;AddNaravelDriverregisters one built-in driver andConfigureNaravelDriversseveral. The overload that takes anIConfigurationbinds the options by reflection, so for trimmed or Native AOT applications bind them yourself and call the overload without it. - One owner for disposal. The manager disposes the drivers its factories created, except the default driver when it was resolved through the direct
TDriverservice: dependency injection owns and disposes that one. A driver that fails to dispose does not stop the others; the manager disposes every driver it owns and then throws oneAggregateExceptionthat holds all the failures. - Errors that name the problem.
DriverNotRegisteredExceptioncarriesDriverName,DriverTypeandAvailableDrivers, and a blank name, a missing default and a missingStoressection each have a fixed message.
Quick start
In a web project (dotnet new web) with this package added, replace Program.cs:
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Naravel.Foundation;
var builder = WebApplication.CreateBuilder(args);
// 1. Register the manager, its driver registry and the configuration section it reads.
builder.Services.AddNaravelManager<GreeterManager, IGreeter, GreeterOptions>(
builder.Configuration.GetSection("Greeter"));
// 2. Register a built-in driver under a name.
builder.Services.AddNaravelDriver<IGreeter>("polite", _ => new PoliteGreeter());
var app = builder.Build();
app.MapGet("/hello", (GreeterManager manager) => manager.Driver("polite").Greet("Ada"));
app.Run();
// 3. The contract, the options and the manager. The manager is only a constructor.
public interface IGreeter { string Greet(string name); }
public sealed class GreeterOptions : ManagerOptions { }
public sealed class GreeterManager(IServiceProvider sp, IDriverRegistry<IGreeter> registry, IOptionsMonitor<GreeterOptions> options)
: Manager<IGreeter, GreeterOptions>(sp, registry, options) { }
public sealed class PoliteGreeter : IGreeter
{
public string Greet(string name) => $"Hello, {name}!";
}
Run it and open /hello: it answers Hello, Ada!. Set "Greeter": { "Default": "polite" } in appsettings.json and manager.Driver() without a name returns the same driver. Greeter is the example's own module, not a shipped one.
Related packages
| Package | Manager built on Foundation | Resolves by name |
|---|---|---|
Naravel.Cache |
CacheManager, LockManager |
ICacheStore, ICacheLock |
Naravel.Database |
DatabaseManager |
IDatabaseConnection |
Naravel.Filesystem |
StorageManager |
IStorageDriver |
Naravel.Mail |
MailManager |
IMailTransport |
Naravel.Queue |
QueueManager |
IQueueDriver |
Naravel.Redis |
RedisManager |
IRedisConnection |
Naravel.Broadcasting |
BroadcastManager |
IBroadcastDriver |
Learn more
- Foundation: English guide, with the errors, the lifetime rules and how to test a module built on it
- Writing a module: module authoring guide, architecture and trimming and AOT
- Changelog · Source and issues · MIT license
Part of Naravel: Laravel's names, .NET's type system. All Naravel packages share one version.
| 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
- Microsoft.Extensions.Configuration (>= 10.0.14)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.14)
- Microsoft.Extensions.Options (>= 10.0.14)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.14)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on Naravel.Foundation:
| Package | Downloads |
|---|---|
|
Naravel.Queue
A Laravel-inspired, driver-based background job queue for .NET. Dispatch, retry with backoff, chaining, batching and a background worker - core package (add Naravel.Queue.Memory for the in-process driver, or Naravel.Queue.Redis/.File/.Database/.RabbitMQ/.Kafka for other backends). |
|
|
Naravel.Cache
Named cache stores, tagging, scoping and locks for Naravel, built on Naravel.Foundation. |
|
|
Naravel.Database
Laravel-style query builder for Naravel on ADO.NET and Dapper: named connections on Naravel.Foundation, a connection and transaction seam that EF Core can share, and per-database driver packages. |
|
|
Naravel.Mail
Typed mail contract for Naravel: Mailable classes, named transports (log, array, SMTP via an optional package) and a test fake, built on Naravel.Foundation. |
|
|
Naravel.Redis
Named, shared Redis connections for Naravel modules: one StackExchange.Redis multiplexer per name, owned and disposed by one manager. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Release notes: https://github.com/km-arc/Naravel/releases/tag/v0.2.0 - full history: https://github.com/km-arc/Naravel/blob/main/CHANGELOG.md