Infrastructure.Service 4.0.1

dotnet add package Infrastructure.Service --version 4.0.1
NuGet\Install-Package Infrastructure.Service -Version 4.0.1
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="Infrastructure.Service" Version="4.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Infrastructure.Service --version 4.0.1
#r "nuget: Infrastructure.Service, 4.0.1"
#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.
// Install Infrastructure.Service as a Cake Addin
#addin nuget:?package=Infrastructure.Service&version=4.0.1

// Install Infrastructure.Service as a Cake Tool
#tool nuget:?package=Infrastructure.Service&version=4.0.1

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.0

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 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. 
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
4.0.1 102 3/12/2024
4.0.0 83 3/12/2024
3.0.2 557 5/23/2022
3.0.1 386 5/23/2022
3.0.0 561 11/2/2021
2.0.0 452 8/21/2021
1.0.3 312 6/22/2021
1.0.2 301 6/21/2021
1.0.1 333 4/24/2021
1.0.0 306 4/24/2021