Skip to content

jin-qu/Linquest.AspNetCore

Repository files navigation

Linquest.AspNetCore

Linquest Asp.Net Core backend.

Build status Coverage Status NuGet Badge GitHub issues GitHub license

GitHub stars GitHub forks

Installation

Package Manager

Install-Package Linquest.AspNetCore

.Net CLI

dotnet add package Linquest.AspNetCore

Getting Started

To add support for linquest queries, you need LinquestActionFilter.

To use callbacks and customizing the request processing;

1. You can inherit your Controller from LinquestController

public class TestController : LinquestController {

  public IQueryable<Company> Companies() {
    // ...
  }
}

2. You can implement ILinquestService interface

public class TestController : ILinquestService {

  public IQueryable<Company> Companies() {
    // ...
  }
  
  // limit the maximum allowed result count, exception will be thrown if given value is exceeded
  public int? MaxResultCount { get; set; }
  
  public event BeforeQueryDelegate BeforeHandleQuery;
  public event BeforeQueryDelegate BeforeQueryExecute;
  public event AfterQueryDelegate AfterQueryExecute;

  void ILinquestService.OnBeforeHandleQuery(BeforeQueryEventArgs args) 
      => BeforeHandleQuery?.Invoke(this, args);

  void ILinquestService.OnBeforeQueryExecute(BeforeQueryEventArgs args) 
      => BeforeQueryExecute?.Invoke(this, args);

  void ILinquestService.OnAfterQueryExecute(AfterQueryEventArgs args) 
      => AfterQueryExecute?.Invoke(this, args);

  public ProcessResult ProcessRequest(ActionContext context) {
    // you can customize processing the request, or use default processor
    return Helper.DefaultRequestProcessor(context, this.HttpContext.RequestServices);
  }
}

If you don't need intercepting the Linquest operations, you can use LinquestActionFilter;

1. With Controller

[LinquestActionFilter]
public class Test2Controller {

  public IQueryable<Company> Companies() {
    // ...
  }
}

2. With Action

public class Test2Controller {

  [LinquestActionFilter]
  public IQueryable<Company> Companies() {
    // ...
  }
}

Processing Values

Linquest handles IQueryable values by default, using QueryableHandler class. You can change handlers by injecting alternative implementations.

Add new IQueryable handler at Startup

public override void ConfigureServices(IServiceCollection services) {
  // ...
  services.AddSingleton<IContentHandler<IQueryable>, ProductHandler>();
}

Add a handler for custom type, like PetaPoco IQuery

public override void ConfigureServices(IServiceCollection services) {
  // ...
  services.AddSingleton<IContentHandler<PetaPoco.IQuery>, PetaPocoQueryHandler>();
}

// ...

public class PetaPocoQueryHandler: IContentHandler<PetaPoco.IQuery> {

  public virtual ProcessResult HandleContent(object query, ActionContext context) {
      return HandleContent((PetaPoco.IQuery)query, context);
  }

  public virtual ProcessResult HandleContent(PetaPoco.IQuery query, ActionContext context) {
    // ...
  }
}

This way, you can apply linquest query parameters to any type.

License

Linquest.AspNetCore is under the MIT License.

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages