You must create a controller factory like
public class MyControllerFactory : DefaultControllerFactory
{
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if (controllerType == null)
throw new InvalidOperationException(string.Format("Page not found: {0}", requestContext.HttpContext.Request.Url.AbsoluteUri.ToString(CultureInfo.InvariantCulture)));
return ObjectFactory.GetInstance(controllerType) as Controller;
}
}
and in golobal.asax in Application_start() add
ObjectFactory.Initialize(x =>
{
x.For<IUserService>().Use<UserService>();
}
ControllerBuilder.Current.SetControllerFactory(new MyControllerFactory());
and in your controller
public class UserController:Controller{
public ContractController(IUserService userService){}
}
now IUserService injected in your controller