Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Replacing IViewComponentHelper can unexpectedly break ViewComponent TagHelpers #5254

Closed
NTaylorMullen opened this issue Sep 8, 2016 · 5 comments
Assignees

Comments

@NTaylorMullen
Copy link
Contributor

If a user replaces the IViewComponentHelper with something that is not IViewContextAware you will get an invalid cast exception at runtime when trying to invoke a ViewComponent TagHelper. We should try to cast the IViewComponentHelper to IViewContextAware and if it can't be cast throw an acceptable exception.

@dougbu
Copy link
Member

dougbu commented Sep 8, 2016

@NTaylorMullen we use (helper as IViewContextAware)?.Contextualize(ViewContext) everywhere else. Why isn't that correct here? Why throw at all?

@NTaylorMullen
Copy link
Contributor Author

Hmm. Odd we do that elsewhere. I feel like throwing to let the user know that their app is incorrectly configured would be better than silently failing.

@NTaylorMullen
Copy link
Contributor Author

Talked offline. You're absolutely right. If a service doesn't need to be contextualized to work then there's no reason for us to throw.

@danroth27
Copy link
Member

danroth27 commented Sep 9, 2016

If a user is using a feature and the component being resolved needs to be ViewContext aware and it isn't then we should throw a reasonable exception.

@danroth27 danroth27 added this to the 1.1.0 milestone Sep 9, 2016
@NTaylorMullen
Copy link
Contributor Author

@danroth27 It's plausible that a user can create an IViewComponentHelper that does not require ViewContext.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants