I'm building an ASP.NET MVC5 application using DDD and I've separated my IoC layer from my web application. In my controllers I have parameterized constructors to receive an instance of my class of services. I am using Ninject, in this I created a class that extends IDependencyResolver, so in my Global.asax I can call the following code:
DependencyResolver.SetResolver(new App.Infra.Ioc.MyDependencyResolver());
Within the MyDependencyResolver class I bind to my dependencies.
The problem is that when I call my action, for example Clientes/Index
, the system returns the error:
Nenhum construtor sem parâmetros foi definido para este objeto.
[MissingMethodException: Nenhum construtor sem parâmetros foi definido para este objeto.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
System.Activator.CreateInstance(Type type) +66
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +110
I know this error occurs because my dependency is not being mapped, but it should work, because in Global.asax I move to DependencyResolver for my dependency injection.
I already implemented in another project using NinjectWebCommon, however, this was within the Asp.Net MVC project. What I want is to implement this on an outside project.
How do I do this?