CommandMiddleware 0.0.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package CommandMiddleware --version 0.0.3
NuGet\Install-Package CommandMiddleware -Version 0.0.3
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="CommandMiddleware" Version="0.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CommandMiddleware --version 0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CommandMiddleware, 0.0.3"
#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 CommandMiddleware as a Cake Addin #addin nuget:?package=CommandMiddleware&version=0.0.3 // Install CommandMiddleware as a Cake Tool #tool nuget:?package=CommandMiddleware&version=0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Register Services
public class Module {
public void ConfigureServices(IServiceCollection services)
{
// Inline service Type
services.RegisterApiService(typeof(DataApiService<>).MakeGenericType(typeof(Department)), "Departments");
// Generic notation
services.RegisterApiService<DataApiService<Department>>("Departments");
// Without prefix
services.RegisterApiService<AuthService>();
// Delegate without DI Container
CommandManager.Register(nameof(FeatureService.FeatureList), FeatureService.FeatureList);
// OR
CommandManager.Register("HelloWorld", (string? name) => "Hello " + name);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.Use(CommandMiddleware.InvokeAsync);
}
}
Examples
API Server
public class DataApiService<T> {
private List<T> data;
public IEnumerable<T> List() => this.data;
public T? Get(in id) => id < this.data.Count ? this.data[id] : null;
public int Add(T entity, int? id) {
if (id > 0){
this.data[id] = entity;
} else {
this.data.Add(entity);
}
return this.data.Count;
}
}
public class AuthService {
public bool Login(string login, string pass) => true;
public bool Logout() => true;
}
public class FeatureService {
public string FeatureList() => new string[] { "RegisterApiService", "Register Delegate", "LightWeight Endpoint" }
}
JS Client
GET
fetch('DepartmentsList')
Result:
{ success: true, result: [{ //Department },...] }
GET + query
fetch('DepartmentsGet?id=1')
Result:
{ success: true, result: { //Department } }
POST + query
fetch('DepartmentsSave?id=1', { headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ //Department }), method: 'POST', credentials: 'include' })
Result:
{ success: true, result: 1 }
GET without prefix
fetch('FeatureList')
Result:
{ success: true, result: [ "RegisterApiService", "Register Delegate", "LightWeight Endpoint" ] }
ERROR
fetch('DepartmentsSave?id=999')
Result:
{ success: false, // Exception details }
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.