dependency injector - Ninject

Nov 29, 2011 at 1:13 PM

Hello friends,


I am using Dependency Injection with Ninject.
But when using ASP.net MVC Awesome (http://awesome.codeplex.com/) I'm in trouble.

I get the error message:
The IControllerFactory 'SportsStore.WebUI.Infrastructure.NinjectControllerFactory' did not return a controller for the name 'AwesomeController'.

He then sends a null controller:

       protected override IController GetControllerInstance(RequestContext requestContext,
            Type controllerType) {

            return controllerType == null
                ? null
                : (IController)ninjectKernel.Get(controllerType);
        }
He tries to access http://localhost:43190/AwesomeController/GetItems but the error appears.

ow can I configure ASP.net MVC with Ninject Awesome to work?


Thank you friends,

Coordinator
Nov 29, 2011 at 1:17 PM

do you have an awesomecontroller ?

 at which line in your view this error occurs ?

probably you've written something wrong in the view

Nov 29, 2011 at 1:22 PM

Yes

this is the name of my controller.

this is my view

      @using (Html.BeginForm())
      {
         @Html.AjaxDropdown("dia", controller: "AwesomeController")
      }

This is a error
The IControllerFactory 'SportsStore.WebUI.Infrastructure.NinjectControllerFactory' did not return a controller for the name 'AwesomeController'.

Nov 29, 2011 at 1:24 PM

this my controller code:

    public class AwesomeController : Controller
    {
        private IProductRepository repository;

        public AwesomeController(IProductRepository repo)
        {
            repository = repo;
        }

        public ViewResult Index()
        {
            ViewBag.Day = GetDay(0);
            return View();
        }


        public ActionResult GetItems(int? key)
        {
            var list = new List<SelectListItem> {new SelectListItem {Text = "not sel", Value = ""}};
            list.AddRange(
                repository.Products.Select(o => new SelectListItem {Text = o.Name, Value = o.ProductID.ToString()}));
            return Json(list);
        }

        private static List<SelectListItem> GetDay(int value)
        {
            var day = new List<SelectListItem>
                          {
                              new SelectListItem {Text = "01", Value = "1", Selected = value == 1},
                              new SelectListItem {Text = "02", Value = "2", Selected = value == 2},
                              new SelectListItem {Text = "03", Value = "3", Selected = value == 3}
                          };
            return day;
        }
    }

Nov 29, 2011 at 1:25 PM

My view code:

@using Omu.Awesome.Mvc.Helpers
@model SportsStore.Domain.Entities.Product

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>Index</title>
    <link href="@Url.Content("~/Content/Awesome.css")" rel="stylesheet" type="text/css" />
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/pepper-grinder/jquery-ui.css" rel="stylesheet" type="text/css" />
   
    <script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui-1.8.16.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/Awesome.js")" type="text/javascript"></script>

</head>
<body>
    <div>
      @using (Html.BeginForm())
      {
         @Html.AjaxDropdown("dia", controller: "AwesomeController")
      }
    </div>
</body>
</html>

Coordinator
Nov 29, 2011 at 1:29 PM

try this: 

@Html.AjaxDropdown("dia", controller: "Awesome")
(whithout "Controller")
Nov 29, 2011 at 1:35 PM

oh man
that my lack of attention.
it worked !!!!!
thank you very much.