Milktea
Milktea

Reputation: 161

"No parameterless constructor defined for this object" when using MVC3 with Ninject

First off, here's the code:

Binding in the NinjectControllerFactory

class MrBigglesworthServices : NinjectModule
{
        public override void Load()
    {
        Bind<IAuthenticationRepository>()
            .To<AuthenticationRepository>()
            .WithConstructorArgument("connectionString",
                ConfigurationManager.ConnectionStrings["VoiceDB"].ConnectionString
                );

        Bind<IAppRepository>()
            .To<AppRepository>()
            .WithConstructorArgument("connectionString",
                ConfigurationManager.ConnectionStrings["SessionStore"].ConnectionString
                );
        }
    }

Constructor for the Search Controller:

private IAppRepository appRepository;

public SearchController(IAppRepository appRepository)
{
    this.appRepository = appRepository;
}

Based on what I've seen with online examples, this should be enough, but for some reason, it's bringing up the error mentioned above. Any suggestions? Please and thank you.

Upvotes: 0

Views: 1728

Answers (1)

Remo Gloor
Remo Gloor

Reputation: 32725

Because you mention using a NinjectControllerFactory I think you are using an incorrect implementation. Consider to switch to https://github.com/ninject/ninject.web.mvc/wiki/MVC3 instead. This is a widely used integration of Ninject and MVC3.

Upvotes: 1

Related Questions