gpt4 book ai didi

asp.net-mvc - 无法使用 MVC 3 Beta 从 Windsor Container 获取 RazorView

转载 作者:行者123 更新时间:2023-12-04 06:44:11 25 4
gpt4 key购买 nike

这就是我的 Application_Start 的外观:

protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();

RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);

_container.Register(Component.For<IWindsorContainer>()
.Instance(_container),
Component.For<IView, IViewPageActivator>()
.ImplementedBy<RazorView>(),
Component.For<IFilterProvider>()
.ImplementedBy<WindsorFilterAttributeFilterProvider>(),
Component.For<IControllerFactory>()
.ImplementedBy<WindsorControllerFactory>(),
Component.For<ControllerContext>()
.ImplementedBy<ControllerContext>()
);


_container.Register(
AllTypes.Of<IController>()
.FromAssembly(Assembly.GetExecutingAssembly())
.Configure(c => c.LifeStyle.Transient)
);

然而,当尝试运行解决方案时,我收到以下错误:
Can't create component 'System.Web.Mvc.RazorView' as it has dependencies to be
satisfied.
System.Web.Mvc.RazorView is waiting for the following dependencies:

Keys (components with specific keys)
- viewPath which was not registered.
- layoutPath which was not registered.
- runViewStartPages which was not registered.
- viewStartFileExtensions which was not registered.

如何设置容器以便它可以在运行时动态获取所需的信息?正如我假设的那样,至少每个 Controller 的 viewPath 都会发生变化。

最佳答案

我仍在使用 MVC,但我认为我可以为您指明正确的方向。

当您为 RazorView 注册组件时,您希望使用 DynamicParamters 方法 - 例如:

Component.For<IView>().ImplementedBy<RazorView>()
.DynamicParameters((kernel, dict) => {
dict["viewPath"] = "~";
dict["layoutPath"] = "~";
dict["runViewStartPages"] = true;
dict["viewStartFileExtensions"] = new List<string>() { "cshtml"};
})

我也没有 Windsor 将 RazorView 转换为 IViewPageActivator,因为它没有实现该接口(interface)。如果您阅读了来自 Brad Wilson 的帖子如果您没有,您的 IDependencyResolver 实现应该为 IViewPageActivator 返回 null。

关于asp.net-mvc - 无法使用 MVC 3 Beta 从 Windsor Container 获取 RazorView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3904111/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com