You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! First off, congrats, this a pretty cool library and I'm currently using it (with joy!) in production. I was wondering if it would be possible to add support for something like the [AsParameters] attribute that was added to AspNetCore from .net 7.0, to augment Minimal APIs. In Asp this attribute allows for grouping all request parameters into one request class/record/struct.
AspNetCore Example:
structTodoItemRequest{publicintId{get;set;}publicstringDescription{get;set;}}app.MapPost("/api/todoitem",async([AsParameters]TodoItemRequestrequest)=>Console.Writeline($"You posted item with Id: {request.Id}, and Description: {request.Description}");
The advantage of being able to do that, is that along with the [FromServices] attribute, you will be able to have for every command delegate only two parameters. One parameter for dependency injecting all the services, and one for grouping all the arguments.
Example of how it could work
//program.csvarservices=newServiceCollection();services.AddLogging();services.AddTransient<TestCommandHandler>();usingvarserviceProvider=services.BuildServiceProvider();ConsoleApp.ServiceProvider=serviceProvider;varapp=ConsoleApp.Create();app.Add("test",async([FromServices]TestCommandHandlercommandHandler,[AsParameters]TestCommandArgsargs)=>awaitcommandHandler.Handle(args));app.Run(args);//in another file...publicrecordTestCommandArgs([Argument]stringParam1,int?Param2):ICommandArgs;publicclassTestCommandHandler(ILogger<TestCommandHandler>logger):ICommandHandler<TestCommandArgs>{publicasyncTaskHandle(TestCommandArgsargs){logger.LogInformation(args.Param1);if(args.Param2.HasValue){logger.LogInformation(args.Param2.ToString());}}}
In the example above TestCommandHandler works as vehicle for injecting all necessary service dependency through its constructor. And TestCommandArgs is the vehicle for grouping all command args that become parameters, into a single record.
As you see in the example the TestCommandHandler and TestCommandArgs also implement some interfaces, name ICommandHandler and ICommandArgs. That's because another advantage of as [AsParameters] attribute is that it allows you to create one standard interface for all your command delegate handlers. Which can increase code readability, code writing speed (through IDE auto-completion) and also maintenance speed when refactoring. Here's some example interfaces for the above:
With is approach - How does one specify an [Argument] vs. an option - today the [Argument] only support parameters, and would also need to be extended to Attributes (of the PoCo)?
Hi! First off, congrats, this a pretty cool library and I'm currently using it (with joy!) in production. I was wondering if it would be possible to add support for something like the [AsParameters] attribute that was added to AspNetCore from .net 7.0, to augment Minimal APIs. In Asp this attribute allows for grouping all request parameters into one request class/record/struct.
AspNetCore Example:
You can see more details here
The advantage of being able to do that, is that along with the [FromServices] attribute, you will be able to have for every command delegate only two parameters. One parameter for dependency injecting all the services, and one for grouping all the arguments.
Example of how it could work
In the example above TestCommandHandler works as vehicle for injecting all necessary service dependency through its constructor. And TestCommandArgs is the vehicle for grouping all command args that become parameters, into a single record.
As you see in the example the TestCommandHandler and TestCommandArgs also implement some interfaces, name ICommandHandler and ICommandArgs. That's because another advantage of as [AsParameters] attribute is that it allows you to create one standard interface for all your command delegate handlers. Which can increase code readability, code writing speed (through IDE auto-completion) and also maintenance speed when refactoring. Here's some example interfaces for the above:
This is by no means a necessity, but it would be a pretty cool feature to add. Thanks!
The text was updated successfully, but these errors were encountered: