2 Replies - 5672 Views - Last Post: 02 August 2012 - 01:19 PM

#1 mvcwannab  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 26-July 12

Ninject IoC pattern issue with wiring up

Posted 02 August 2012 - 09:20 AM

Hello again,
I am trying to use Ninject in a MVC application and I keep getting a "Sequence contains no elements" error.
Code I'm using:
public class MvcApplication : NinjectHttpApplication
    {
        protected override IKernel CreateKernel()
        {
            IKernel kernel = new StandardKernel(new NinjectBindings());
            // tried with and without this line below active
            kernel.Load(Assembly.GetExecutingAssembly());
            return kernel;
        }

        protected override void OnApplicationstarted()
        {
            base.OnApplicationstarted();
            AreaRegistration.RegisterAllAreas();

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
...
public class NinjectBindings : NinjectModule
    {
        public override void Load()
        {
            Bind<ITicketRepository>().To<TicketRepository>();
            Bind<IUserRepository>().To<UserRepository>();
        }
    }



What I'm trying to accomplish is having a controller injected with the appropriate repository depending on the controller. I have several of them that I need to wire up, but at this point in the process I only have one for users and one for tickets/orders. I have a common repository that I plan to use for all of the different types, using generics. I have tried with and without the [Inject] attribute on the controllers themselves, to no avail.

Thank you for any advice you could give, I've been trying to work this issue out now for almost a week. I'm tempted to just drop it and create a new interface to each concrete class, which will defeat the purpose of using IoC, but if that's how I can get it to work, for now it'll have to do.

Is This A Good Question/Topic? 0
  • +

Replies To: Ninject IoC pattern issue with wiring up

#2 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1252
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: Ninject IoC pattern issue with wiring up

Posted 02 August 2012 - 12:46 PM

On what line is the error firing? Your code should be working fine.

Quote

Sequence contains no elements

Was This Post Helpful? 0
  • +
  • -

#3 mvcwannab  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 26-July 12

Re: Ninject IoC pattern issue with wiring up

Posted 02 August 2012 - 01:19 PM

the issue in debug hits on return kernel;. The next line should be the onstart function, but it goes into Ninject.Web.Common.cs to debug within the Ninject.Web.Common reference.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1