FluentPermissions 1.0.0-preview.1.2602211042

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

FluentPermissions

简体中文

FluentPermissions is a Roslyn incremental source generator for permission modeling in .NET. You define permissions with a fluent DSL, and get compile-time generated constants + read-only query APIs.

What It Generates

  • Namespace: $(AssemblyName).Security
  • Entry type: public static partial class AppPermissions
  • Flat permission code constants
  • Read-only descriptors: AppPermissions.All
  • Common lookup/query members:
    • AppPermissions.ByCode
    • AppPermissions.AllCodes, AppPermissions.GetAllCodes()
    • AppPermissions.Contains(code)
    • AppPermissions.TryGet(code, out descriptor)
    • AppPermissions.GetByCode(code)
    • AppPermissions.GetChildren(parentCode)
    • AppPermissions.GetLeaves()

Repository Layout

  • FluentPermissions.Core (netstandard2.0): contracts + fluent builder DSL
  • FluentPermissions (netstandard2.0): source generator
  • FluentPermissions.Sample (net9.0): usage sample
  • FluentPermissions.Tests (net9.0): generator tests

Quick Start

  1. Add references
  • Reference FluentPermissions.Core in your app project
  • Add FluentPermissions as source generator (analyzer/NuGet)
  1. Define a single options type
using FluentPermissions.Core.Abstractions;

public sealed class SampleOptions : PermissionOptionsBase
{
    public int DisplayOrder { get; set; }
    public string? Icon { get; set; }
    public bool IsHighRisk { get; set; }
}
  1. Implement registrar
using FluentPermissions.Core.Abstractions;
using FluentPermissions.Core.Builder;

public sealed class AppPermissionDefinition : IPermissionRegistrar<SampleOptions>
{
    public void Register(PermissionBuilder<SampleOptions> builder)
    {
        builder
            .DefineGroup("System", "System", "Core system settings", system =>
            {
                system.WithOptions(o =>
                {
                    o.DisplayOrder = 10;
                    o.Icon = "fa-gear";
                });

                system.DefineGroup("Users", "User management", users =>
                {
                    users.AddPermission("Create", "Create user");
                    users.AddPermission("Delete", "Delete user", "High risk", o => o.IsHighRisk = true);
                });
            })
            .DefineGroup("Reports", reports =>
            {
                reports.AddPermission("View", "View reports");
                reports.AddPermission("Export", "Export reports");
            });
    }
}
  1. Consume generated API
using MyApp.Security;

var code = AppPermissions.System_Users_Create; // APP:System:Users:Create

if (AppPermissions.TryGet(code, out var descriptor))
{
    Console.WriteLine(descriptor!.DisplayOrName);
    Console.WriteLine(descriptor.Parent);
}

foreach (var c in AppPermissions.GetAllCodes())
    Console.WriteLine(c);

Global Generation Option (Attribute)

Use PermissionGenerationOptionsAttribute to control whether groups themselves are emitted as permission items.

  • Default: true
  • If false:
    • group descriptors are not emitted into AppPermissions.All
    • group constants are not emitted
    • only leaf permission constants/descriptors remain

You can place it on assembly or registrar class.

using FluentPermissions.Core.Abstractions;

[assembly: PermissionGenerationOptions(false)]
// or: [PermissionGenerationOptions(false)] on registrar class

Generated Model

PermissionDescriptor:

  • Code: full code (e.g. APP:System:Users:Create)
  • Name: logical name (e.g. Create)
  • DisplayName: optional display name
  • Parent: parent code (e.g. APP:System:Users)
  • IsLeaf: whether this is a leaf permission
  • IsGroup => !IsLeaf
  • DisplayOrName => DisplayName ?? Name

Notes

  • Analyzer diagnostics include consistency checks for generic options across registrars (FP0002).

License

MIT

There are no supported framework assets in this 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
1.0.0-preview.1.2602211042 148 2/21/2026
1.0.0-preview.1.2602191410 73 2/19/2026
1.0.0-preview.1.2509210917 160 9/21/2025
1.0.0-preview.1.2509210705 141 9/21/2025
1.0.0-preview.1.2509210644 147 9/21/2025
1.0.0-beta.3 145 9/21/2025
1.0.0-beta.2 177 9/20/2025
1.0.0-beta.1 174 9/20/2025