ninject.web.mvc

Ninject “No parameterless constructor defined for this object.”

大憨熊 提交于 2019-12-19 19:46:11
问题 I'm testing Ninject, but following the how-to, i find it impossible to make it work. The information on the web is so messy even contradictory. I'm developping a website in MVC 4 on visual studio 2012 and i did install Ninject using Nuget. So I get an error : "No parameterless constructor defined for this object.". As soon as I enter my controller. I did the necessary steps : Nuget installation in NinjectWebCommon.cs, I did register my Interface in the RegisterServices method. In my

Ninject “No parameterless constructor defined for this object.”

谁都会走 提交于 2019-12-19 19:44:42
问题 I'm testing Ninject, but following the how-to, i find it impossible to make it work. The information on the web is so messy even contradictory. I'm developping a website in MVC 4 on visual studio 2012 and i did install Ninject using Nuget. So I get an error : "No parameterless constructor defined for this object.". As soon as I enter my controller. I did the necessary steps : Nuget installation in NinjectWebCommon.cs, I did register my Interface in the RegisterServices method. In my

Inject dependency into DelegatingHandler

…衆ロ難τιáo~ 提交于 2019-12-19 02:03:16
问题 I am new to dependency injection, but happy with Ninject and Ninject.Extensions.Logging to [Inject] my ILogger wherever i need it. However some DelegatingHandlers are spoiling all the fun. public class HttpsHandler : DelegatingHandler { [Inject] public ILogger Logger { get; set; } protected override Task<HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken cancellationToken) { if (!string.Equals(request.RequestUri.Scheme, "https", StringComparison.OrdinalIgnoreCase))

Do I need to register Ninject.OnePerRequestModule with Ninject.Web.MVC 3.0?

天涯浪子 提交于 2019-12-19 01:43:17
问题 I'm using Ninject for DI and the Ninject.MVC3 extension within an MVC4 app, specifically version 3.0.0.6. Reading the documentation on Ninject's wiki, it appears that the lifetime of objects created with InRequestScope are actually controlled by ASP.NET and to properly clean up one should register the OnePerRequest HttpModule. However it looks like this doco is out of date as type="Ninject.OnePerRequestModule"/> cannot be found. On the other hand I read some bits recently that seemed to

Do I need to register Ninject.OnePerRequestModule with Ninject.Web.MVC 3.0?

故事扮演 提交于 2019-12-19 01:42:03
问题 I'm using Ninject for DI and the Ninject.MVC3 extension within an MVC4 app, specifically version 3.0.0.6. Reading the documentation on Ninject's wiki, it appears that the lifetime of objects created with InRequestScope are actually controlled by ASP.NET and to properly clean up one should register the OnePerRequest HttpModule. However it looks like this doco is out of date as type="Ninject.OnePerRequestModule"/> cannot be found. On the other hand I read some bits recently that seemed to

NinjectDependencyResolver fails binding ModelValidatorProvider

江枫思渺然 提交于 2019-12-17 18:16:22
问题 I'm developing an ASP.NET Web Api 2.2 with C#, .NET Framework 4.5.1. After updating my Web.Api to Ninject 3.2.0 I get this error: Error activating ModelValidatorProvider using binding from ModelValidatorProvider to NinjectDefaultModelValidatorProvider A cyclical dependency was detected between the constructors of two services. Activation path: 3) Injection of dependency ModelValidatorProvider into parameter defaultModelValidatorProviders of constructor of type DefaultModelValidatorProviders 2

Ninject MVC 2, EF 4, AutoMapper - ObjectContext has been disposed

偶尔善良 提交于 2019-12-12 18:28:29
问题 Completely revised: Okay, I'm using Ninject with the MVC 2 extension as my DI container, and AutoMapper as my entity <--> view model mapper. I'm getting an 'ObjectContext is disposed' error in my view model -> entity mapping. My code is below. Ninject bindings: public class DIModule : NinjectModule { public override void Load() { this.Bind<HGEntities>().ToSelf().InRequestScope(); this.Bind<IArticleRepository>().To<HGArticleRepository>().InRequestScope(); this.Bind<IGameRepository>().To

Issues after installing ninject mvc 3 in mvc 5 project

元气小坏坏 提交于 2019-12-12 13:19:22
问题 I have created new asp mvc 5 project. Project target .NET 4.5. I installed ninject mvc 3 nuget package. But when I run project I get this error in NinjectWebCommon.cs in CreateKernel() method: An exception of type 'System.IO.FileLoadException' occurred in Ninject.dll but was not handled in user code Additional information: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's

Randomly-Occurring Ninject Exception: “Error loading Ninject component ICache”

穿精又带淫゛_ 提交于 2019-12-12 10:38:47
问题 I recently added both Ninject and Ninject.Web.Mvc to an existing ASP.NET MVC 4 web application. When browsing the site, I receive the following exception, seemingly at random: [InvalidOperationException: Error loading Ninject component ICache No such component has been registered in the kernel's component container. Suggestions: 1) If you have created a custom subclass for KernelBase, ensure that you have properly implemented the AddComponents() method. 2) Ensure that you have not removed the

Ninject for Web Site and Api - Sequence contains no elements

[亡魂溺海] 提交于 2019-12-12 09:52:46
问题 I have a single VS2010 solution with a Web.Api project and an MVC 3 project. Both the Web.APi and the MVC project have their own App_Start with NinjectWebCommon in and their own bindings declared in there. When trying to use the Api I always get the following message: Sequence contains no elements Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.