ninject / Ninject.Web.Mvc

extension for ninject providing integration with ASP.NET MVC
http://ninject.org/
Other
238 stars 85 forks source link

Sequence contains no elements - Bootstrapper #24

Closed thomen closed 12 years ago

thomen commented 12 years ago

System.Linq.Enumerable.Single(IEnumerable`1 source) +379 Ninject.Web.Mvc.NinjectMvcHttpApplicationPlugin.Start() in c:\Projects\Ninject\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\NinjectMvcHttpApplicationPlugin.cs:53

I cannot seem to get this up and running. I've followed the instructions to the letter..

nothing changed in global I'm using the App_Start folder

[assembly: WebActivator.PreApplicationStartMethod(typeof(EFWebApp.Web.App_Start.NinjectWebCommon), "Start")] [assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(EFWebApp.Web.App_Start.NinjectWebCommon), "Stop")]

namespace EFWebApp.Web.App_Start { using System; using System.Web;

using Microsoft.Web.Infrastructure.DynamicModuleHelper;

using Ninject;
using Ninject.Web.Common;

public static class NinjectWebCommon
{
    private static readonly Bootstrapper bootstrapper = new Bootstrapper();

    /// <summary>
    /// Starts the application
    /// </summary>
    public static void Start()
    {
        DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
        DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
        bootstrapper.Initialize(CreateKernel);
    }

    /// <summary>
    /// Stops the application.
    /// </summary>
    public static void Stop()
    {
        bootstrapper.ShutDown();
    }

    /// <summary>
    /// Creates the kernel that will manage your application.
    /// </summary>
    /// <returns>The created kernel.</returns>
    private static IKernel CreateKernel()
    {
        var kernel = new StandardKernel();
        kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
        kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

        RegisterServices(kernel);
        return kernel;
    }

    /// <summary>
    /// Load your modules or register your services here!
    /// </summary>
    /// <param name="kernel">The kernel.</param>
    private static void RegisterServices(IKernel kernel)
    {
        kernel.Load<EFWebNinjectModule>();
    }
}

}

remogloor commented 12 years ago

This means that the DataAnnotationsModelValidatorProvider is removed by someother library or you use App_Start and derive from NinjectHttpApplication at the same time.

svallory commented 12 years ago

How do I find out / fix if DataAnnotationsModelValidatorProvider was removed?

remogloor commented 12 years ago

If I remember correctly this can occur if you derive from NinjectWebApplication in addition to using App_Start.

Have you verified that you don't derive from NinjectWebApplication?

2012/11/19 Saulo Vallory notifications@github.com

How do I find out / fix if DataAnnotationsModelValidatorProvider was removed?

— Reply to this email directly or view it on GitHubhttps://github.com/ninject/ninject.web.mvc/issues/24#issuecomment-10503709.

svallory commented 12 years ago

Yes. That's why I asked about the DataAnnotationsModelValidatorProvider removed thing :/

Couldn't solve the issue, so I uninstalled Ninject and started adding todo's where I'm hard coding the instantiation to deal with this later. Any help will be much appreciated!

svallory commented 12 years ago

Found the problem! I have tree projects in my solution (Domain, Infra and UI). I accidentally installed Ninject in two of them (infra and UI) which created two NinjectWebCommon classes. This was the cause of the issue. Once I removed the ninject package from infra, the problem was solved. :)

ryno1234 commented 10 years ago

@svallory thank you for the update! This helped me

mesoamerica commented 10 years ago

The easiest solution is to delete the NinjectWebCommon.cs class created under the App_Start directory and allow the MvcApplication inheriting from NinjectHttpApplication to let Ninject take care of calling your NinjectModule modules where you register your bindings.

jfaenomoto commented 10 years ago

@svallory just passing by to thanks. I'm actually new to Ninject and was getting this Exception while loading my application. Removed duplicated NinjectWebCommon class and worked! ;)

himonline33 commented 9 years ago

@svallory This was Helpfull Thanks ^^.