I had a problem with the controller:
An error occurred while trying to create a controller of type '* .WebMvc.Controllers.HomeController'. Make sure that the controller does not have a constructor without parameters.
Find a solution for ApiController, but nothing was found about the normal controller.
Created a new MVC 4 project from scratch.
HomeController.cs:
public class HomeController : Controller { private IAccountingUow _uow; public HomeController(IAccountingUow uow) { _uow = uow; }
UnityDependencyResoler.cs:
public class UnityDependencyResolver : IDependencyResolver { private IUnityContainer _container; public UnityDependencyResolver(IUnityContainer container) { _container = container; RegisterTypes(); } public object GetService(Type serviceType) { try { return _container.Resolve(serviceType); }catch { return null; } } public IEnumerable<object> GetServices(Type serviceType) { try { return _container.ResolveAll(serviceType); }catch { return null; } } private void RegisterTypes() { _container.RegisterType<IAccountingUow, AccountingUow>(); } }
Global.asax
protected void Application_Start() {
It is debugged and it turns out that IAKountingUow attempts are not even made.
What am I doing wrong? Thinking about it all day.
c # dependency-injection asp.net-mvc-4 unity-container
Yaroslav Nov 12 '12 at 12:31 2012-11-12 15:31
source share