mardi 17 mai 2016

Can't create component as it has dependencies to be satisfied. Parameter which was not provided

I have just started using Windsor to resolve dependency. But i am getting below error while passing string value in my Controller.I checked couple of similar Windsor Post but no luck.

public class HomeController : Controller
{
    public readonly String _A = string.Empty;
    public HomeController(string A)
    {
        this._A = A;        
    }
}

Installer

public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.Register(Classes.FromThisAssembly()
            .BasedOn<IController>()
            .LifestyleTransient());
    } 

WindsorControllerFactory

public class WindsorControllerFactory : DefaultControllerFactory
    {
        private readonly IKernel kernel;

        public WindsorControllerFactory(IKernel kernel)
        {
            this.kernel = kernel;
        }

        public override void ReleaseController(IController controller)
        {
            kernel.ReleaseComponent(controller);
        }

        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            if (controllerType == null)
            {
                throw new HttpException(404, string.Format("The controller for path '{0}' could not be found.", requestContext.HttpContext.Request.Path));
            }
            return (IController)kernel.Resolve(controllerType);
        }
    }

Do i need to wrap 'A' inside a class and resolve it's respective Interface ?

Aucun commentaire:

Enregistrer un commentaire