I am developing an application that has 4 layers Dominio, Infra, Servico e Web
When I have access a route for example Home/Index
it says that there is no constructor without parameters, my constructor looks like this:
public HomeController(IPessoaServico pessoaServico)
{
this.pessoaServico = pessoaServico;
}
I have a class NinjectWebCommon.cs
in the App_Start
folder with the following code.
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(Web.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(Web.App_Start.NinjectWebCommon), "Stop")]
namespace Web.App_Start
{
using System;
using System.Web;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using Ninject;
using Ninject.Web.Common;
using Infra.Banco.Interface;
using Infra.Banco;
using Infra.Repositorio.Interface;
using Infra.Repositorio;
using Servico.Interface;
using Servico;
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();
try
{
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
RegisterServices(kernel);
return kernel;
}
catch
{
kernel.Dispose();
throw;
}
}
/// <summary>
/// Load your modules or register your services here!
/// </summary>
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IDataBaseFactory>().To<DataBaseFactory>().InRequestScope();
kernel.Bind<IUnitOfWork>().To<UnitOfWork>().InRequestScope();
kernel.Bind<IPessoaRepositorio>().To<PessoaRepositorio>();
kernel.Bind<IPessoaServico>().To<PessoaServico>();
}
}
I've just put one of the entities for example, this is the first time I'm making an application like this and I think I'm letting something go if someone can help me if you need more information and just talk.
EDIT: I searched a little and saw some people indicating the installation of 2 additional packages Ninject MVC 5 and Ninject WEB.API, I'm adding the 2 for testing.