Ninject for website and Api-Sequence contains no elements

I have one VS2010 solution with Web.Api project and MVC 3 project.

Both Web.APi and the MVC project have their own App_Start with NinjectWebCommon inside and their own bindings declared there.

When I try to use Api, I always get the following message:

The sequence contains no elements.

Description: An unhandled exception occurred during the execution of the current web request. View the stack trace for more information about the error and its occurrence in the code.

Exception Details: System.InvalidOperationException: Sequence Contains No Elements

Source Error:

Line 30: DynamicModuleUtility.RegisterModule (typeof (OnePerRequestHttpModule)); Line 31: DynamicModuleUtility.RegisterModule (typeof (NinjectHttpModule)); Line 32: bootstrapper.Initialize (CreateKernel); Line 33:} Line 34:

Source file: D: \ Code \ GreenDeal \ PoS \ GreenDeal.UI \ App_Start \ NinjectWebCommon.cs Line: 32

Stack trace:

[InvalidOperationException: The sequence contains no elements] System.Linq.Enumerable.Single (IEnumerable 1 source) +371 Ninject.Web.Mvc.NinjectMvcHttpApplicationPlugin.Start() in c:\Projects\Ninject\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\NinjectMvcHttpApplicationPlugin.cs:53 Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable 1 series, Action 1 action) in c:\Projects\Ninject\ninject\src\Ninject\Infrastructure\Language\ExtensionsForIEnumerableOfT.cs:32 Ninject.Web.Common.Bootstrapper.Initialize(Func 1 createKernelCallback) in c: \ Projects \ Ninject \ Ninject.Web.Common \ src \ Ninject.Web.Common \ Bootstrapper.cs: 53 XXXX.UI.App_Start. NinjectWebCommon.Start () in D: \ Code \ XXXX \ PoS \ XXXX.UI \ App_Start \ NinjectWebCommon.cs: 32

I do not get this error if I remove WebActivator.PreApplicationStartMethod from the Api or MVC site.

I assume there is a problem with two starts, but I'm not sure what to do? Can I make them coexist? Should I split into two solutions and hope that it disappears? When deployed, the site and api will be hosted on separate servers, and the site will use api.

+3
source share
1 answer

Returned to the basics.

The following are the steps indicated here: http://www.eyecatch.no/blog/2012/06/using-ninject-with-webapi-rc/

There were still problems, but this was due to the fact that the client had a link to ninject.webapi on the MVC site. Deleted it and everything works.

+1
source

Source: https://habr.com/ru/post/1205782/


All Articles