LinqExpressionParser.AspNetCore 0.1.0

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

LinqExpressionParser.AspNetCore

LinqExpressionParser.AspNetCore is class library project that you can use in your ASP.NET Core app to modelbind and authorize about ExpressionParseResult. see LinqExpressionParser

Dependency

  • ASP.NET Core 7.0 ~ 8.0

Getting start

var builder = WebApplication.CreateBuilder(args);

//builder.Services.AddExpressionParse();
builder.Services.AddExpressionParse(options => {
    // configure ExpressionParseOptions
});

builder.Services.AddExpressionAuthorization(options => {
    // configure ExpressionAuthorizationOptions
}, pb => {
    // configure PermissionBuilder
});
[Route("[Controller]")]
public class UserController : Controller
{
    private List<User> _users = new() {...}

    [HttpGet]
    public IActionResult Get([FromQuery] ValueParseResult<User, bool> predicate)
    {
        return Ok(_users.Where(predicate.GetExpression()))
    }
}

See sample for more information

Configuration

See LinqExpressionParser

Authorization

builder.Services.AddExpressionAuthorization(options => {
    // Set PermissionFinder to get permission from ClaimsPrincipal
    options.PermissionFinder = user => ...;
    // options.PermissionComparsion = ...;
    // Default comparsion is StringComparsion.OrdinalIgnoreCase
}, pb => {
    // Set global permission for every IExpressionParseResult<Expression>
    pb.Global("Global0", "Global1");
    
    // Set entity permission for expression that contains User or IEnumerable<User>
    pb.Entity<User>("User");

    // Set property permission for expression that contains Item.Price property
    EntityPermissionProviderBuilder itemPermission = pb.Entity<Item>();
    itemPermission.Property(i => i.Price, "ItemPrice")

    pb.Assertion(info => {
        // Return true if user required theses permissions
    }, "Assertion0", "Assertion1");
});

You can add ExpressionAllowAnonymousAttribute for controller, action or action parameter to ignore authorize.

//[ExpressionAllowAnonymous]
public class UserController : ControllerBase
{
    //[ExpressionAllowAnonymous]
    public IActionResult Get(
        /*[ExpressionAllowAnonymous]*/
        ValueParseResult<User, bool> predicate)
    {
        ...
    }
}

Property, field can not authorize automatic. use IAuthorizationService to authorize manualy

public class UserController : ControllerBase
{
    public ValueParseResult<User, bool> Predicate { get; set; }

    private readonly IAuthorizationService _authorizationService;

    public UserController(IAuthorizationService authorizationService)
    {
        _authorizationService = authorizationService;
    }

    public Task<IActionResult> Get()
    {
        var authorizeResult = await _authorizationService.AuthorizeAsync(User, Predicate, ExpressionAuthorizationDefaults.AUTHORIZE_POLICY);

        if (!authorizeResult.Successed)
        {
            // Handle result
        }
        return ...
    }
}
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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.

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.1.0 245 1/16/2024