ninject

I need more Ninject practical examples

无人久伴 提交于 2019-12-09 15:59:12
问题 In the past, I used swiftsuspenders that is an actionscript 3 IoC controller. Basically the first version of switfsuspender had something similar to the Ninject kernel that was called injector. If I wanted to create an application injector (with let's say the most relevant mappings to be used throughout the application), I had to inject the injector itself in the application classes. I am wondering now what is the practice to use kernel.get<> among several classes in the application. Should I

No matching bindings are available, and the type is not self-bindable in Ninject

可紊 提交于 2019-12-09 15:34:55
问题 I am using Ninjec, Ninject.Web.MVC and Ninject.Web.Common When I start my mvc application I get this binding error: What do I wrong in my binding? Error activating DbConnection No matching bindings are available, and the type is not self-bindable. Activation path: 4) Injection of dependency DbConnection into parameter existingConnection of constructor of type DbContext 3) Injection of dependency DbContext into parameter dbContext of constructor of type GenericRepository{User} 2) Injection of

AutoMapper 4.2 and Ninject 3.2

戏子无情 提交于 2019-12-09 09:05:58
问题 I'm updating a project of mine to use AutoMapper 4.2, and I'm running into breaking changes. While I seem to have resolved said changes, I'm not entirely convinced I've done so in the most appropriate way. In the old code, I have a NinjectConfiguration , and an AutoMapperConfiguration class that are each loaded by WebActivator. In the new version the AutoMapperConfiguration drops out and I instead instance a MapperConfiguration directly in the NinjectConfiguration class where the bindings are

Entity Framework Context in Singleton

♀尐吖头ヾ 提交于 2019-12-09 06:54:49
问题 I'm building a App that use Context of EF in Singleton Pattern like NHibernate work with Session: public class DbContextFactory { private static volatile DbContextFactory _dbContextFactory; private static readonly object SyncRoot = new Object(); public DbContext Context; public static DbContextFactory Instance { get { if (_dbContextFactory == null) { lock (SyncRoot) { if (_dbContextFactory == null) _dbContextFactory = new DbContextFactory(); } } return _dbContextFactory; } } public DbContext

Simple Injector FilterInjection seems to be reinitialising RegisterPerWebRequest injected item

元气小坏坏 提交于 2019-12-09 06:39:25
I'm trying to move from Ninject to Simple Injector but I'm experiencing an odd issue when trying to duplicate functionality that worked with Ninject. In Ninject I had a service which contained: private readonly ICollection<Message> messages; This service was registered as Bind<INotificationService>().To<NotificationService>() .InRequestScope(); This service allowed messages (UI and error) to be passed back to the MVC site. This service was injected into an ActionFilterAttribute: kernel.BindFilter<CriticalErrorAttribute>(FilterScope.Last, 1) .When((context, ad) => !string.IsNullOrEmpty(ad

DbContext Disposed after first request when using Ninject's InRequestScope()

こ雲淡風輕ζ 提交于 2019-12-09 06:22:17
问题 I am new to both EF and Ninject so forgive me if this does not make sense :) I have an MVC3 application with the Ninject and Ninject.Web.Common references. I am trying to inject a DbContext into my repositories. What I am seeing is that on the first request, everything works wonderfully but the subsequent requests return: System.InvalidOperationException: The operation cannot be completed because the DbContext has been disposed. at System.Data.Entity.Internal.LazyInternalContext

session-per-request implementation for WCF, NHibernate, and Ninject

ぃ、小莉子 提交于 2019-12-09 05:27:58
问题 I am trying to implement a session-per-request model in my WCF application, and I have read countless documents on this topic, but looks like there is not a complete demonstration of this. I actually came across some very useful articles such as this one: NHibernate's ISession, scoped for a single WCF-call but these are all from the old days when NHibernate and Ninject did not have WCF specific implementations, therefore they achieved what I need by implementing their custom service providers

Ninject crashes on application start on appharbor

旧巷老猫 提交于 2019-12-09 05:17:11
问题 I am using Ninject on my MVC 3 project deployed on appharbor. I noticed that I get an exception when the application is started, and it looks like something inside Ninject is the cause, but I cannot find any answers out there - so please help me :) Will try to add the complete exception here: Server Error in '/' Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the

How to use a factory with Dependecy Injection without resorting to using Service Locator pattern

不想你离开。 提交于 2019-12-09 05:09:06
问题 I have a GUI application. In it I allow a user to select from a container-provided list of algorithms. Each algorithm will be kicked off as a background task in another view. I need to support multiple instances of this view, and support multiple instances of the same algorithm. That view will also be provided by the container. The algorithm is also stateful. So I have a case where I need to create instances of my view and algorithm and bind them together at runtime. I don't have static

NInject: how to pass parameters when Get<T>()?

时光总嘲笑我的痴心妄想 提交于 2019-12-09 05:02:22
问题 I'm using the attached image to explain what I meant. I have a few classes managed by NInject. Some of them have a few singleton instances, and others are in transient scope. In the image, blue rectangles are singltons, red are transient. The Processor depends on other classes or instances. I want to get the instance of Processor each time by using kernel.Get. However, each time I want to use different values for the objects used by the Processor. See Action1 and Action2 in the image. The