ninject.web.mvc

Using ninject with Ninject.Web.Api for Web Api 2 is not working in ASP.NET MVC 5

℡╲_俬逩灬. 提交于 2021-02-18 07:06:20
问题 I am developing an Asp.NET MVC project. My project has web api as well. I am using ASP.NET MVC5 and Web Api 2 with Visual Studio 3. I am doing dependency injection using ninject. I know ninject for web is not working for Web Api 2. So I tried to use Ninject for Web Api. I installed ninject for web api 2 package using nuget package manager Then I installed Ninject.Web using nuget package manager Then in NinjectWebCommon, I added this line in RegisterServices private static void

Ninject: entity object cannot be referenced by multiple instances of IEntityChangeTracker

ε祈祈猫儿з 提交于 2020-01-21 20:35:48
问题 I am starting to use Ninject in my MVC5 code-first app. Here's my NinjectWebCommon.cs: private static IKernel CreateKernel() { var kernel = new StandardKernel(); try { kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel); kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>(); kernel.Bind<CMSContext>() .ToSelf() //.InSingletonScope(); .InRequestScope(); kernel.Bind<IExecutiveRepository>() .To<ExecutiveRepository>(); kernel.Bind

Ninject: entity object cannot be referenced by multiple instances of IEntityChangeTracker

限于喜欢 提交于 2020-01-21 20:35:26
问题 I am starting to use Ninject in my MVC5 code-first app. Here's my NinjectWebCommon.cs: private static IKernel CreateKernel() { var kernel = new StandardKernel(); try { kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel); kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>(); kernel.Bind<CMSContext>() .ToSelf() //.InSingletonScope(); .InRequestScope(); kernel.Bind<IExecutiveRepository>() .To<ExecutiveRepository>(); kernel.Bind

How does Ninject create controller in ASP.NET MVC?

断了今生、忘了曾经 提交于 2020-01-10 18:24:46
问题 This may be stupid question, but I am looking at Ninject sources and don't see NInject registering its own controller factory. I also don't see any IControllerFactory class in Ninject.Web.Mvc assembly. Am I missing something? How does Ninject create controller and inject parameters into constructor? 回答1: Lets say we are looking for "/Task/Index". Ninject MVC applications use now DefaultControllerFactory , the same as non-Ninject applications. DefaultControllerFactory finds type for controller

Ninject.Web.MVC4 disposes my DbContext exactly once

心已入冬 提交于 2020-01-04 14:12:31
问题 There are a half dozen identical questions, I know. I've followed the advice of their answers, and I'm still stuck. I've used NuGet to install Ninject.Web.MVC4 and added my bindings to NinjectWebCommon.RegisterServices . I've manually added the following to system.web/httpModules <httpModules> <add name="OnePerRequestModule" type="Ninject.OnePerRequestModule"/> </httpModules> I've wrapped my bindings in a Ninject GlobalKernelRegistrationModule<OnePerRequestHttpModule> My DataContext: public

Cannot Inject Dependencies using Ninject into ASP.NET Web API Controller called from Angular Service

落花浮王杯 提交于 2020-01-01 16:50:34
问题 I am using Ninject together with ASP.NET MVC 4. I am using repositories and want to do constructor injection to pass in the repository to one of the controllers. Here is my context object (EntityFramework) that implements my StatTracker interface: public class StatTrackerRepository : IStatTrackerRepository { private GolfStatTrackerEntities _ctx; public StatTrackerRepository(GolfStatTrackerEntities ctx) { _ctx = ctx; } public IQueryable<Facility> GetFacilites() { return _ctx.Facilities; } }

Cannot Inject Dependencies using Ninject into ASP.NET Web API Controller called from Angular Service

北城以北 提交于 2020-01-01 16:50:07
问题 I am using Ninject together with ASP.NET MVC 4. I am using repositories and want to do constructor injection to pass in the repository to one of the controllers. Here is my context object (EntityFramework) that implements my StatTracker interface: public class StatTrackerRepository : IStatTrackerRepository { private GolfStatTrackerEntities _ctx; public StatTrackerRepository(GolfStatTrackerEntities ctx) { _ctx = ctx; } public IQueryable<Facility> GetFacilites() { return _ctx.Facilities; } }

How to inject ModelState as parameter with Ninject?

余生颓废 提交于 2019-12-31 03:26:10
问题 Im very new to Ninject. I want to find a way to pass Modelstate of a controller further to service layer. what i have right now: private readonly IAccountService service; public AccountController(ILanguageService ls, ISessionHelper sh) { this.service = new AccountService(new ModelStateWrapper(this.ModelState)); this.languageService = ls; this.sessionHelper = sh; } public AccountService(IValidationDictionary validationDictionary) { this.validationDictionary = validationDictionary; } want i

Ninject - dynamically specifying a connection string based on a sub domain

最后都变了- 提交于 2019-12-30 07:16:22
问题 I'm trying to specify a connection string dynamically based of the url using ninject. I'm using the ninject.mvc nuget package that uses the webActivator. My code is as follows: my injection: kernel.Bind<IUnitOfWork>().To<UnitOfWork>() .WithConstructorArgument("connectionString", MvcApplication.GetConnectionStringName()); my global.asax private static HttpContext _context; public static string GetConnectionStringName() { var subDomain = String.Empty; if (_context != null) { subDomain =

How to configure Ninject so that it creates a single instance per Controller

走远了吗. 提交于 2019-12-29 01:44:09
问题 I'm trying to use Ninject for an MVC5 application and I want to know if there's any way I can configure it so that instantiate a single object per Controller (I'm not sure if it the same as per request), use that instance in any Action of the controller and once the Action has finished release all the resources that the object utilized. The class that I want Ninject to inject in my controllers implements the IDisposable interface. So far I have tried this: private static void RegisterServices