gpt4 book ai didi

asp.net-mvc-3 - 找不到支持服务 System.Web.Mvc.IControllerFactory 的组件

转载 作者:行者123 更新时间:2023-12-01 11:43:24 25 4
gpt4 key购买 nike

我在温莎城堡遇到了问题。请帮我!我正在使用 CaSTLe Windsor 3.2.0.0、.Net 4.0 和 Mvc 3.0.0.0

非常感谢!

问题:找不到支持服务 Mvc IControllerFactory 的组件这里有一些代码。

public class WindsorDependencyResolver : IDependencyResolver
{
private readonly IWindsorContainer _container;
public WindsorDependencyResolver(IWindsorContainer container)
{
this._container = container;
}

public object GetService(Type serviceType)
{
return _container.Resolve(serviceType);
}

public IEnumerable<object> GetServices(Type serviceType)
{
return _container.ResolveAll(serviceType).Cast<object>();
//return _container.ResolveAll<object>(serviceType);
}
}

//Castle Windsor register
protected void Application_Start()
{
var container = new WindsorContainer();

container.AddFacility<TypedFactoryFacility>()
.Register(Component.For<IServiceFactory>().AsFactory().LifeStyle.Transient);

//Do register the service/type to container
container.Register(
Types.FromThisAssembly()
.BasedOn(typeof(Controller))
.WithService.Self().LifestyleTransient());

container.Register(
Component.For<IRepository>()
.ImplementedBy<GenericRepository>().DependsOn(Dependency.OnValue("context", "ProjectContext"))
.LifeStyle.PerWebRequest);

container.Register(
Types.FromAssembly(Assembly.GetAssembly(typeof(IUserService)))
.BasedOn(typeof(ServiceBase))
.WithService.DefaultInterfaces().LifestylePerWebRequest());

DependencyResolver.SetResolver(new WindsorDependencyResolver(container));
}

最佳答案

远离 DependencyResolver...改用 ControllerFactory。

查看 tutorial

关于asp.net-mvc-3 - 找不到支持服务 System.Web.Mvc.IControllerFactory 的组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17418916/

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