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

Enable creating a ViewResult without requiring a view engine #617

Closed
puncsky opened this issue Jun 5, 2014 · 6 comments
Closed

Enable creating a ViewResult without requiring a view engine #617

puncsky opened this issue Jun 5, 2014 · 6 comments

Comments

@puncsky
Copy link

puncsky commented Jun 5, 2014

After "#597 Remove ActionResultHelper", helpers in ActionResultHelper are merged to Controller.cs.

We find that actually return new ViewResult(_serviceProvider, _viewEngine) in public ViewResult View(string view, object model) is useless. And return new ViewResult() is enough because ViewResult itself has DI on its ctor and the services can be reached through Context.ApplicationServices.

@puncsky puncsky changed the title _serviceProvider, _viewEngine could be removed from Controller.cs _serviceProvider and _viewEngine could be removed from Controller.cs Jun 5, 2014
@yishaigalatzer
Copy link
Contributor

  1. Make sure we don't get rid of the overload that takes in a view engine, because that's a way to customize the view result.
  2. We should discuss this, as this is an anti pattern to DI and should only be used in specific cases (like when we want to be lazy). Speaking of lazy there is a very similar pattern in view components, where we take the full set of services (including view engine) where we are many times not going to use it.

@rynowak
Copy link
Member

rynowak commented Jun 6, 2014

The advantage of it would be the ability to just say new ViewResult(MyModel) for POCO scenarios.

We could keep both overloads but it's a little strange to have an optional service passed.

@yishaigalatzer
Copy link
Contributor

@rynowak I see your point. Lets get together with @loudej and discuss the design alternatives.

@pranavkm
Copy link
Contributor

I had to deal with this when working with Activate (https://github.com/aspnet/Mvc/pull/648/files#r13678472). A POCO controller is forced to activate the service provider + ViewEngine to be able to produce a View rather than call the view result which eventually does have enough knowledge to obtain these values.

@yishaigalatzer
Copy link
Contributor

@rynowak lets do it, touch base with @loudej but this keeps coming up.

@rynowak
Copy link
Member

rynowak commented Jun 27, 2014

this is happening.

rynowak added a commit that referenced this issue Jun 28, 2014
We want result types to be constructable without services.
@rynowak rynowak closed this as completed Jun 28, 2014
@danroth27 danroth27 modified the milestones: 6.0.0-alpha2, 1.0.0-alpha2, 6.0.0-alpha3 Jul 7, 2014
@danroth27 danroth27 changed the title _serviceProvider and _viewEngine could be removed from Controller.cs ViewResult can be constructed without a view engine Aug 17, 2014
@danroth27 danroth27 changed the title ViewResult can be constructed without a view engine Enable creating a ViewResult without requiring a view engine Aug 17, 2014
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

5 participants