Infrastructure.Service
4.0.4
dotnet add package Infrastructure.Service --version 4.0.4
NuGet\Install-Package Infrastructure.Service -Version 4.0.4
<PackageReference Include="Infrastructure.Service" Version="4.0.4" />
paket add Infrastructure.Service --version 4.0.4
#r "nuget: Infrastructure.Service, 4.0.4"
// Install Infrastructure.Service as a Cake Addin #addin nuget:?package=Infrastructure.Service&version=4.0.4 // Install Infrastructure.Service as a Cake Tool #tool nuget:?package=Infrastructure.Service&version=4.0.4
Infrastructure Service
Appendium
- Overview
- Installation
- Basic Usage
Overview
- Open end-point API allow build dynamic query for searching and paging. It auto compile query from text on Front-end to Expression Tree Linq.
- Integration with Infrastructure.Repository
- Support .NetCore if you want run on .NetFramework you need override the Repository Layer
Installation
To install Infrastructure Service Infrastructure.Service library, right-click on your project in Solution Explore,then select Manage NuGet Packages..., and install the following package.
- Infrastructure.Service
You can also install this library using .NET CLI
dotnet add package Infrastructure.Service --version 4.0.4
Setup code base, It similar version 3.x.x
Basic Usage
- End-point API will be public with append some query params: filters, sorts, pageSize, pageIndex. You can view more BaseCriteria's class
- You should take care some class:
- BaseCriteria: the query params for api
- PagedList: the response model
- ISearchService: the service handler logic.
Simple Query
Single query
When querying data using Linq, everything can be express look like below
var result = context.Users.Where(s => s.Website == "www.mnlifeblog.com");
Infrastructure.Service look like:
- JSON: {"Key":"website","Operate":"eq","Value":"www.mnlifeblog.com"}
- Example API: {{host}}/users?filters={"Key":"website","Operate":"eq","Value":"www.mnlifeblog.com"}
Multiple query
Note that it's also possible to query data using multiple predicates:
var result = context.Users.Where(s => s.Website == "www.mnlifeblog.com" ||
s.Name == "mnlifeblog");
That code can be used when using Infrastructure.Service
- JSON: {"or":[{"Key":"website","Operate":"eq","Value":"www.mnlifeblog.com"},{"Key":"name","Operate":"eq","Value":"mnlifeblog"}]}
- Example API: {{host}}/users?filters={"or":[{"Key":"website","Operate":"eq","Value":"www.mnlifeblog.com"},{"Key":"name","Operate":"eq","Value":"mnlifeblog"}]}
Operand summary table
Operate | Translate | Description |
---|---|---|
eq | == | Equals |
neq | != | Not Equals |
gt | > | Greater Than |
gte | >= | Greater Than Equals |
lt | < | Less Than |
lte | ⇐ | Less Than Equals |
in | Contains | Contains |
nin | !Contains | Not Contains |
btw | >= ⇐ | Between |
Sorts
Sort by ASC or DESC
When use orderby on Linq:
var result = context.Users.Orderby(s => s.Website);
The code can be use on Infrastructure.Service:
- JSON: {"key":"website","criteria":"asc"}
- Example API: {{host}}/users?sorts={"key":"website","criteria":"asc"}
When you want to apply DESC for sort you just alter asc to desc.
Multiple sort
The strongly typed LINQ:
var result = context.Users.Orderby(s => s.Website).ThenByDescending(s => s.Date);
The code you can build:
- JSON: [{"key":"website","criteria":"asc"},{"key":"date","criteria":"desc"}]
- Example API: {{host}}/users?sorts=[{"key":"website","criteria":"asc"},{"key":"date","criteria":"desc"}]
Paging
Depend on pageIndex and pageSize field for paging
- Example API: {{host}}/users?pageIndex=1&&pageSize=20
The payload response:
{
"paged": {
"totalCount": 42,
"count": 10,
"pageIndex": 1,
"pageSize": 10,
"durationMilliseconds": 10,
"queryMilliseconds": 8,
"totalMiliseconds": 10
}
}
Validation
You can restrict some fields and not allow search by SearchRestrictions's section on appsetting.json
"SearchRestrictions": {
"User": "name, id, date ",
}
Take note: the fields separated by a comma and it not case sensitive
The user's property on JSON will be matched to the name of the entity.
public class User : IEntity<Guid>
{
public Guid Id { get; set; }
public string Name { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
...
}
Throw exception message: "<font color=red>The field is restricted!</font>" when you access to field restricted.
Source: https://github.com/KhaMinhVLU-2017/Infrastructure.Service
<font color=#0fb503>Thanks for watching</font>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Infrastructure.Repository (>= 1.0.12)
- Microsoft.CSharp (>= 4.7.0)
- Microsoft.EntityFrameworkCore (>= 3.1.14)
- Newtonsoft.Json (>= 13.0.1)
- System.Linq.Dynamic.Core (>= 1.4.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.