✅ Use() Extension Overload
I'm working with the Use method in ASP.NET Core and have encountered two overloads. The first, taking HttpContext and RequestDelegate, is clear to me. However, I'm struggling to understand the second overload where the use lambda accepts HttpContext and Func<Task>. Some articles mention that this approach leads to additional allocations per request. Could someone elaborate on what these extra allocations are and how they impact performance?
6 Replies
The extra allocations are due to how a
Func<>
is created dynamically. Extra allocations means more work allocating the object and for the GC later. That said, the difference is negligible for most applications. Use whichever is easiest for you and don't worry about perf issues until you have identified that there is one.what dose this means
perf
short-hand for "performance"
this are memory stuff and GC
yes. and again, you really shouldn't need to worry about it for most applications. get something working first, then if you identify a performance issue, address it at that time.
any ways the recommended by the docs is to use the one that takes the HttpContext and a RequestDelegate , and thank you