Open TheTrigger opened 3 years ago
Not sure if I follow. Using the ApiResponse
object is optional. For as long as you integrate AutoWrapper, your controller method can use IActionResult or any type that you'd like your action to return.
Sorry, I could be missing something, here the current situation:
I'm using UseCustomSchema = true
to return my custom PaginatedApiResponse
in a controller's endpoint
public class PaginatedApiResponse : ApiResponse
{
public PaginatedApiResponse(object data, Pagination pagination) : base(result: data)
{
Pagination = pagination ?? throw new System.ArgumentNullException(nameof(pagination));
}
public Pagination Pagination { get; set; }
}
Cause of this I have to return a new ApiResponse(obj)
for every controller to correctly wrap objects. It's dirty.
Meanwhile, if I use UseCustomSchema = false
i don't need to explicitly return an ApiResponse
in every controller, because the return object is automatically wrapped. (if false
, returning a PaginatedApiResponse
loses extra properties, eg Pagination
)
So my idea would be to remove UseCustomSchema
and properly check at runtime the type of the returning object if is not IApiResponse
then wrap it. (require an empty IApiResponse
and not ApiResponse
, so we could still apply custom mappings)
Doing this we could use custom schemas and keep the transparency
What do you think about it?
I see what you mean. I will look into this when I have some time. It's been very busy at work. I' am on the process on converting this to .NET 5. Would be nice if you could implement the feature, test them and submit a PR. Alternatively, you could fork the repo for the time being and implement the feature you need to get going.
I will try to figure out how to implement those things, hope I can help
@TheTrigger I've released an RC version just to test out the migration to .NET 5. You can try using it to test this request out as well: https://www.nuget.org/packages/AutoWrapper.Core/5.0.0-rc
Hello, I would suggest implementing a check to automatically recognize wrapper objects
How?
Something at runtime like
returnObject is IApiResponse
then use it, otherwise wrap it.IApiResponse
must have no props definedWhy?
if we not forced to use
UseCustomSchema = true
for occasional custom schemes, don't need to rewrite every Controller's methods return type, keeping the solution clean and not invasive.Not sure if it already possible in some way, I just started to use this lib