CommandMiddleware 0.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package CommandMiddleware --version 0.0.4                
NuGet\Install-Package CommandMiddleware -Version 0.0.4                
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.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CommandMiddleware --version 0.0.4                
#r "nuget: CommandMiddleware, 0.0.4"                
#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.4

// Install CommandMiddleware as a Cake Tool
#tool nuget:?package=CommandMiddleware&version=0.0.4                

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

  1. GET

     fetch('DepartmentsList')
    

    Result:

     {
     	success: true,
     	result: [{
     		//Department
     	},...]
     }
    
  2. GET + query

     fetch('DepartmentsGet?id=1')
    

    Result:

     {
     	success: true,
     	result: {
     		//Department
     	}
     }
    
  3. POST + query

     fetch('DepartmentsSave?id=1', {
     		headers: {
     			'Content-Type': 'application/json'
     		},
     		body: JSON.stringify({
     			//Department
     		}),
     		method: 'POST',
     		credentials: 'include'
     	})
    

    Result:

     {
     	success: true,
     	result: 1
     }
    
  4. GET without prefix

     fetch('FeatureList')
    

    Result:

     {
     	success: true,
     	result: [ "RegisterApiService", "Register Delegate", "LightWeight Endpoint" ]
     }
    
  5. ERROR

     fetch('DepartmentsSave?id=999')
    

    Result:

     {
     	success: false,
     	// Exception details
     }
    
Product 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 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. 
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.0.9 107 9/19/2024
0.0.8 97 9/18/2024
0.0.7 95 9/18/2024
0.0.6 97 9/18/2024
0.0.5 100 9/17/2024
0.0.4 96 9/17/2024
0.0.3 93 9/17/2024
0.0.2 98 9/17/2024
0.0.1 106 9/16/2024