I looked into what MapGet() is doing and found that one of the overloads takes a Delegate type (class, not keyword, and not a RequestDelegate), but then pass it on to MapMethods(), which takes a RequestDelegate. What I find very confusing is how this cast takes place. A RequestDelegate has the signature delegate Task RequestDelegate(HttpContext httpContext). When casting a delegate to another, don't they a) need the same signature, b) actually need to pass a reference to the Invoke() method of the delegate (that is to say you can't just convert a delegate to another despite their signatures matching, or so I read).
Another thing I find extremely confusing is how one can pass in an arbitrary request handler to the Minimal API and it somehow being converted to a RequestDelegate. The documentation from Microsoft shows examples where the handler has no arguments like () => ..., and also arbitrary arguments which will be resolved through the dependency injection mechanism like (MyClass a, HttpContext ctx, DbContext<MyClass> dbCtx) => .... I would assume this handler is somehow wrapped in another lambda that fits the RequestDelegate signature, so that ASP.NET Core can pass in a HttpContext and the wrapping lambda can then analyze the lambda passed in by the developer and decide how to resolve its depencies and such. But I have no clue at all where or how this happens. It literally just takes in a Delegate and passes it into another method which takes a RequestDelegate, and magically it's now a valid RequestDelegate?
Anyone knows?