fslang-suggestions icon indicating copy to clipboard operation
fslang-suggestions copied to clipboard

Implement implicit conversion between F# fun to .NET generic Func<> for ASP.NET minimal API.

Open oleksandr-bilyk opened this issue 2 years ago • 5 comments

I propose F# implicitly cast F# fun with parameter attributes to C# delegate. It will help to write ASP.NET minimal API in short way

image

To do the same on F# I must create separate function. image

C# looks better for this image

oleksandr-bilyk avatar Nov 10 '23 14:11 oleksandr-bilyk

@oleksandr-bilyk I think right now it does already do it, if you pass the lambda in the call.

Also, should this work with any delegate type instead? I'm not keen on "Func is better" stuff which is already having few edge cases in overload resolution.

smoothdeveloper avatar Nov 10 '23 16:11 smoothdeveloper

Likely a special case for #1131

smoothdeveloper avatar Nov 10 '23 16:11 smoothdeveloper

You can write some code to work around this if you want, like I did in https://github.com/brianrourkeboll/FSharp.AspNetCore.WebAppBuilder; a few others have experimented with similar things, I believe, including @lucasteles, who opened #1131.

brianrourkeboll avatar Nov 10 '23 17:11 brianrourkeboll

Also note that AFAIK the attributes currently are not captured, i.e. since FromServices will be correctly inferred everything will work as expected.

gurustron avatar Feb 26 '24 11:02 gurustron

@brianrourkeboll Yes, I ended up creating this https://github.com/lucasteles/FSharp.MinimalApi also

lucasteles avatar Mar 20 '24 22:03 lucasteles