Farsight.Common 0.9.7-beta

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

Farsight.Common

NuGet .NET License

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:

  1. Setup — Parallel preparation work
  2. Initialize — Ordered initialization
  3. 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 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. 
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
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