Design extensibility for executors #6822
Conversation
/cc @pranavkm |
I did one as an example. If we like the pattern I will go ahead and port the rest. |
{ | ||
public interface IActionResultExecutor<TResult> where TResult : IActionResult | ||
{ | ||
Task ExecuteAsync(ActionContext context, TResult result); |
rynowak
Sep 14, 2017
Author
Member
Most of the executors we have already follow this pattern, I'm just adding an interface.
I have big plans for these..... (trails off in a sinister way)
Most of the executors we have already follow this pattern, I'm just adding an interface.
I have big plans for these..... (trails off in a sinister way)
I like it! The formatting pipeline infrastructure is still a bit too tightly coupled to MVC, IMO. Have you guys thought about decoupling it so it could be used in other MW as well? (I'm guessing aspnet/Diagnostics#346 (comment) is related to this?) |
Yes, but it's not planned for right now
conneg is one of a few things in MVC that has an opinion at all. There's no technical need for it to be coupled, but we'd have to re-examine those decisions. |
|
||
namespace Microsoft.AspNetCore.Mvc.Infrastructure | ||
{ | ||
public interface IActionResultExecutor<TResult> where TResult : IActionResult |
pranavkm
Sep 14, 2017
Member
Is there any value in making this contravariant? Maybe for scenarios like IActionResultExecutor<NotFoundResult> = new StatusCodeResultExecutor();
Is there any value in making this contravariant? Maybe for scenarios like IActionResultExecutor<NotFoundResult> = new StatusCodeResultExecutor();
rynowak
Sep 14, 2017
Author
Member
Hmm, I don't think it can hurt.
Hmm, I don't think it can hurt.
602dd8a
to
2dcc293
@pranavkm ping |
410e738
to
82c44cb
Looks good |
public override void ExecuteResult(ActionContext context) | ||
{ | ||
if (context == null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
var executor = context.HttpContext.RequestServices.GetRequiredService<RedirectResultExecutor>(); | ||
executor.Execute(context, this); | ||
var services = context.HttpContext.RequestServices; |
pranavkm
Sep 21, 2017
Member
Could we have these call the executor and block on it? In the default case, it should be fine since the executor is entirely synchronous.
Could we have these call the executor and block on it? In the default case, it should be fine since the executor is entirely synchronous.
rynowak
Sep 21, 2017
Author
Member
I don't want to put a .Result
in the code. You could implement these interfaces and do some arbitrary stuff
I don't want to put a .Result
in the code. You could implement these interfaces and do some arbitrary stuff
@@ -145,5 +145,25 @@ | |||
"TypeId": "public class Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata : Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata", | |||
"MemberId": "public override Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.IModelBindingMessageProvider get_ModelBindingMessageProvider()", | |||
"Kind": "Removal" | |||
}, | |||
{ |
{ | ||
await executor.ExecuteAsync(context, view, this); | ||
} | ||
var executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<ViewResult>>(); |
pranavkm
Sep 21, 2017
Member
Nice
Nice
@@ -176,6 +178,29 @@ public virtual Task ExecuteAsync(ActionContext actionContext, IView view, ViewRe | |||
viewResult.StatusCode); | |||
} | |||
|
|||
/// <inheritdoc /> | |||
public async Task ExecuteAsync(ActionContext context, ViewResult result) |
pranavkm
Sep 21, 2017
Member
Could we remove the now unused overload since the type was in .Internal
?
Could we remove the now unused overload since the type was in .Internal
?
rynowak
Sep 21, 2017
Author
Member
Sure
Sure
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.AspNetCore.Mvc.Internal | ||
namespace Microsoft.AspNetCore.Mvc.Infrastructure |
pranavkm
Sep 21, 2017
Member
Is the namespace change to facilitate subclassing?
Is the namespace change to facilitate subclassing?
rynowak
Sep 21, 2017
Author
Member
Yes
Yes
We have all of these executors but they aren't really documented/supported for extensibility today. This change introduces a pattern for action result executors so we can make them extensible.
We have all of these executors but they aren't really
documented/supported for extensibility today. This change introduces a
pattern for action result executors so we can make them extensible.