Farsight.Common
0.9.7-beta
dotnet add package Farsight.Common --version 0.9.7-beta
NuGet\Install-Package Farsight.Common -Version 0.9.7-beta
<PackageReference Include="Farsight.Common" Version="0.9.7-beta" />
<PackageVersion Include="Farsight.Common" Version="0.9.7-beta" />
<PackageReference Include="Farsight.Common" />
paket add Farsight.Common --version 0.9.7-beta
#r "nuget: Farsight.Common, 0.9.7-beta"
#:package Farsight.Common@0.9.7-beta
#addin nuget:?package=Farsight.Common&version=0.9.7-beta&prerelease
#tool nuget:?package=Farsight.Common&version=0.9.7-beta&prerelease
Farsight.Common
A .NET 10 library providing shared runtime types and a Roslyn incremental source generator for Farsight-style hosted applications. The generator discovers annotated types and auto-registers services and configuration bindings at compile time, eliminating runtime reflection and manual DI registration. Fully compatible with AOT compilation.
Features
- Compile-time service registration — Annotated singletons and options are registered via source generation
- Zero runtime reflection — All discovery happens at build time
- AOT compatible — No reflection-based code paths; safe for native AOT publishing
- Strict configuration binding — Unknown configuration keys fail at startup
- Validation support — Data annotations and FluentValidation integration
🚀 Quick Start
1. Install the Package
dotnet add package Farsight.Common
2. Define Your Configuration
using Farsight.Common;
using System.ComponentModel.DataAnnotations;
[ConfigOption(SectionName = "MyApp")]
public class AppOptions
{
[Required]
public string Endpoint { get; set; } = string.Empty;
}
3. Create a Service
using Farsight.Common;
public sealed partial class Worker : Singleton
{
[Inject]
private readonly AppOptions _options;
protected override Task RunAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Running on: {Endpoint}", _options.Endpoint);
return Task.CompletedTask;
}
}
4. Wire Up Your Application
using Farsight.Common;
using Farsight.Common.Startup;
var builder = Host.CreateApplicationBuilder(args);
builder.AddApplication<BasicFarsightStartup>();
await builder.Build().RunAsync();
📋 What Gets Generated
| Attribute | What It Does |
|---|---|
[ConfigOption] |
Binds config section → options class with validation |
[ConfigOption<TValidator>] |
Adds FluentValidation support |
Singleton (base class) |
Registers as singleton + generates constructor injection |
[Inject] |
Auto-wires dependencies into private fields |
🏗️ Application Lifecycle
BasicFarsightStartup orchestrates your Singleton services through three phases:
- Setup — Parallel preparation work
- Initialize — Ordered initialization
- Run — Long-running execution
public sealed partial class MyService : Singleton
{
protected override Task SetupAsync(CancellationToken ct)
=> Task.CompletedTask;
protected override Task InitializeAsync(CancellationToken ct)
=> Task.CompletedTask;
protected override Task RunAsync(CancellationToken ct)
=> Task.CompletedTask;
}
🔧 Advanced Configuration
FluentValidation Support
[ConfigOption<MyOptionsValidator>(SectionName = "Features")]
public class MyOptions
{
public string Value { get; set; } = string.Empty;
}
public class MyOptionsValidator : AbstractValidator<MyOptions>
{
public MyOptionsValidator() => RuleFor(x => x.Value).NotEmpty();
}
Design-Time Configuration
For EF tooling or design-time scenarios:
builder.AddApplicationOptions(); // Only config, no services
📦 Requirements
- .NET 10.0+
- The source generator is included automatically
📝 License
MIT License — see LICENSE for details.
| 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
- FluentValidation (>= 12.1.1)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.4)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.4)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.4)
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 |
|---|---|---|
| 0.9.7-beta | 51 | 3/27/2026 |
| 0.9.6-beta | 50 | 3/17/2026 |
| 0.9.5-beta | 282 | 3/14/2026 |
| 0.9.4-beta | 55 | 3/12/2026 |
| 0.9.3-beta | 113 | 2/22/2026 |
| 0.9.2-beta | 58 | 2/21/2026 |
| 0.9.1-beta | 58 | 2/20/2026 |
| 0.9.0-beta | 56 | 2/14/2026 |