Closed GoogleCodeExporter closed 8 years ago
I have same paroblem. ViewRegistrationSource.RegistrationsFor doesn't call for
Layout type.
Original comment by achmedzh...@gmail.com
on 30 Dec 2011 at 6:48
Thanks for the report and repro Pawel (sorry about the extended delay in
responding.) I'm not 100% certain that DI will be possible in this scenario,
I'll take a look at it ASAP.
Original comment by nicholas...@gmail.com
on 23 Jan 2012 at 5:21
Any update on this?
Original comment by sebastia...@gmail.com
on 6 Mar 2012 at 1:22
Having the same issue. Any ideas?
Original comment by jaben.ca...@captiveaire.com
on 27 Apr 2012 at 9:40
Original comment by travis.illig
on 21 Sep 2012 at 4:34
The only temporary solution I've found is to inject dependencies into a base
controller and pass them into ViewData. Looking forward for the fix.
Original comment by alexey.s...@gmail.com
on 27 Sep 2012 at 8:09
It does not appear that this issue has been addressed in the new v3 autofac mvc
integration.
Original comment by quen...@screenfeed.com
on 13 Dec 2012 at 9:11
Original comment by alex.meyergleaves
on 14 Dec 2012 at 4:50
There still seems to be no hook to achieve this. The layout view is not
requested from the dependency resolver.
Original comment by alex.meyergleaves
on 19 Dec 2012 at 12:33
[deleted comment]
In MVC5 there still doesn't appear to be a hook into the DependencyResolver to
get Razor layouts.
From what I can tell, Razor goes like this:
* A System.Web.Mvc.RazorView gets created by the
System.Web.Mvc.RazorViewEngine.CreateView().
* The view gets the Render method called on it, where the BuildManager reads
the markup and compiles the type as necessary, then the ViewPageActivator
passes the whole thing through the DependencyResolver. That all happens in the
System.Web.Mvc.BuildManagerViewEngine class, from which all other view engines
derive (ASPX and Razor).
* The RazorView has RenderView() called and gets a ViewContext, a TextWriter,
and the actual instance of the view that was created by the ViewPageActivator.
Here's where it takes a turn.
* In RenderView, there's a mechanism that gets the start page
("_ViewStart.cshtml") using the System.Web.WebPages.StartPage.GetStartPage
method. To instantiate that start page, it uses an IVirtualPathFactory, which
defaults to a wrapper around the BuildManager. This part of the page
instantiation does not pass through DependencyResolver.
* The RazorView then calls ExecutePageHierarchy (from WebPageBase) and passes
the start page in.
* Each start page then recursively executes in this fashion via the
ExecutePageHierarchy method. Nowhere in here does it touch DependencyResolver.
Now, technically we could do some fanciness around that IVirtualPathFactory
where we could try to insert ourselves in there, but there's no documentation
around that except "This type/member supports the .NET Framework infrastructure
and is not intended to be used directly from your code." It would be fairly
complex and potentially risky if those aren't supposed to be used - we'd end up
with stuff that could break on new releases and be hard to maintain.
Given this has been open for two years now and there's no real way to fix it, I
vote we close the issue as WontFix and possibly update the wiki with this as a
known issue.
Original comment by travis.illig
on 3 Dec 2013 at 12:28
Sounds good to me.
Original comment by pa...@pabich.eu
on 3 Dec 2013 at 12:41
[deleted comment]
Original comment by travis.illig
on 4 Dec 2013 at 11:31
Original issue reported on code.google.com by
pa...@pabich.eu
on 24 Nov 2011 at 11:28Attachments: