KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Before I set up the question you should know that I got my current code from this page: http://www.strathweb.com/2012/05/using-ninject-with-the-latest-asp-net-web-api-source/ I'm trying to use ASP.NET Web API and Ninject in my application by using an IDependencyResolver adapter found on the site above. I created all the code just like it shows on the site and it works but when I load up my appication my regular controllers fail and show this error: [MissingMethodException: No parameterless constructor defined for this object.] [InvalidOperationException: An error occurred when trying to create a controller of type 'AccountManager.Controllers.HomeController'... So, it seems like I can use Ninject with regular controllers or Web API controllers but not both. :( Here is my code: NinjectResolver.cs public class NinjectResolver : NinjectScope, IDependencyResolver { private IKernel _kernel; public NinjectResolver(IKernel kernel) : base(kernel) { _kernel = kernel; } public IDependencyScope BeginScope() { return new NinjectScope(_kernel.BeginBlock()); } } NinjectScope.cs public class NinjectScope : IDependencyScope { protected IResolutionRoot resolutionRoot; public NinjectScope(IResolutionRoot kernel) { resolutionRoot = kernel; } public object GetService(Type serviceType) { IRequest request = resolutionRoot.CreateRequest(serviceType, null, new Parameter[0], true, true); return resolutionRoot.Resolve(request).SingleOrDefault(); } public IEnumerable<object> GetServices(Type serviceType) { IRequest request = resolutionRoot.CreateRequest(serviceType, null, new Parameter[0
Tags (comma-separated)
Save Edits
Cancel