MVC3 Areas problem
I am building an application with MVC3 and I have a problem when I want to add an area.
I am adding a UsersArea everything works fine but when I try to run the Web Site I get the following error :
No component for key userscontroller was found
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Castle.MicroKernel.ComponentNotFoundException: No component for key userscontroller was found
Source Error:
Line 160: public IController CreateController(RequestContext context, string controllerName) Line 161: { Line 162: return IoC.Resolve((controllerName + "Controller").ToLower()); Line 163: } Line 164:
Here is my Windsor code :
protected override IWindsorContainer CreateContainer(string windsorConfig)
{
IWindsorContainer container = new WindsorContainer();
container.Register(Component.For<IUnitOfWorkFactory>()
.ImplementedBy<NHibernateUnitOfWorkFactory>());
container.Register(Component.For<IProductRepository>()
.ImplementedBy<ProductRepository>()
.LifeStyle.Is(LifestyleType.Transient));
container.Register(Component.For<ICustomerService>()
.ImplementedBy<CustomerService>()
.LifeStyle.Is(LifestyleType.Transient));
container.Register(Component.For<ICustomerRepository>()
.ImplementedBy<CustomerRepository>()
.LifeStyle.Is(LifestyleType.Transient));
开发者_JAVA技巧
container.Register(Component.For<ICategoryRepository>()
.ImplementedBy<CategoryRepository>()
.LifeStyle.Is(LifestyleType.Transient));
container.Register(Component.For<IOrderRepository>()
.ImplementedBy<OrderRepository>()
.LifeStyle.Is(LifestyleType.Transient));
container.Register(Component.For<ILogger>()
.ImplementedBy<NLogLogger>()
.LifeStyle.Is(LifestyleType.Transient));
container.Register(AllTypes.Of<IController>()
.FromAssembly(typeof(HomeController).Assembly)
.Configure(t => t.Named(t.Implementation.Name.ToLower())
.LifeStyle.Is(LifestyleType.Transient)));
return container;
}
public class RhinoIoCControllerFactory : IControllerFactory
{
public IController CreateController(RequestContext context, string controllerName)
{
return IoC.Resolve<IController>((controllerName + "Controller").ToLower());
}
public void ReleaseController(IController controller)
{
IoC.Container.Release(controller);
}
public SessionStateBehavior GetControllerSessionBehavior(RequestContext requestContext, string controllerName)
{
return SessionStateBehavior.Default;
}
}
精彩评论