ninject

An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key

北城以北 提交于 2019-12-17 03:22:34
问题 Using EF5 with a generic Repository Pattern and ninject for dependency injenction and running into an issue when trying to update an entity to the database utilizing stored procs with my edmx. my update in DbContextRepository.cs is: public override void Update(T entity) { if (entity == null) throw new ArgumentException("Cannot add a null entity."); var entry = _context.Entry<T>(entity); if (entry.State == EntityState.Detached) { _context.Set<T>().Attach(entity); entry.State = EntityState

The static container already has a kernel associated with it

瘦欲@ 提交于 2019-12-14 03:56:33
问题 I have this error related to Ninject when deploy to Azure: The static container already has a kernel associated with it! But it works fine in local. And it has always been working on both local and Azure before, and I don't remember what changes happened recently (e.g., I didn't NuGet a newer version of Ninject). I checked related posts but still cannot solve my problem. Here is the error page when after deployed to Azure: Server Error in '/' Application. The static container already has a

Ninject Contextual Binding on MVC Request

狂风中的少年 提交于 2019-12-14 03:49:12
问题 I have an unusual situation injecting a service into an ASP.NET MVC Controller. The Controller provides a single action to render a side-bar menu on the page, and the service injected into the Controller is a factory to create the side-bar content. The action is decorated with the [ChildActionOnly] attribute: the side bar can only be rendered when rendering another action. The difficulty comes in that I want to inject different instances of the side-bar factory abstraction according to the

Ninject: GetAll instances that inherit from the same abstract class

☆樱花仙子☆ 提交于 2019-12-14 03:20:34
问题 Is it possible for Ninject to get all instances that inherit from a specific Abstract Class? For example, I have the following Abstract Class. public abstract class MyAbstractClass { } Then I have the following two derived classes that both inherit from the same abstract class. public class MyDerivedClass1 : MyAbstractClass { } public class MyDerivedClass2 : MyAbstractClass { } Now I am going to bind both derived classes with the Kernel because I want them to be in singleton scope. _kernel =

Ninject and ChildKernel in MVC3 project: “Error loading Ninject component ICache”

て烟熏妆下的殇ゞ 提交于 2019-12-14 03:12:15
问题 I'm using Ninject (3.0) in my ASP.Net MVC3 project. At some point of request handling I want to execute some tasks. I'm using session-per-request pattern but don't want these tasks to share the same Session as current Request has. So, I thought, ChildKernels could help me with this issue. I was going to create another binding for ISession in child kernel, but started with that: var child = new Ninject.Extensions.ChildKernel.ChildKernel(NinjectMVC3.Kernel); child.Dispose(); If I execute the

Ninject not binding object in BaseController in MVC3

荒凉一梦 提交于 2019-12-14 02:52:14
问题 I just upgraded my MVC2 project to MVC3 and used the NuGet library package reference to install ninject. This created an appstart class and i used the following code to inject my IMembershipService class. public static void RegisterServices(IKernel kernel) { kernel.Bind<IMembershipService>().To<AccountMembershipService>(); } This works great with my HomeController, for example. public class HomeController : Controller { public IMembershipService MembershipService { get; set; } public

Dependency Inject with Ninject 2.0

天涯浪子 提交于 2019-12-14 02:47:43
问题 A little question regarding Ninject. I use a WCF 'duplex channel' to communicate with a service. The channel is defined as an interface, lets call it IMyChannel for simplicity. To instantiate a channel we use DuplexChannelFactory<IMyChannel> object's CreateChannel() method. So far I have manage to bind the factory class with this. Bind< DuplexChannelFactory< IMyChannel>>().ToMethod(context => new DuplexChannelFactory< IMyChannel>( new MessageEndPoint(), new NetTcpBinding(), "net.tcp:/

Using NSubstitute and Ninject to return a value

て烟熏妆下的殇ゞ 提交于 2019-12-14 02:23:06
问题 In my NinjectDependencyResolver: IDependencyResolver I have a AddBindings() method that for now I want it to return some hard coded values for me until I connect it to DB later. The class and interface I want to mock and use in that AddBindings() method are like this: public class Configuration { public string WebSiteNotActiveMessage { get; set; } public bool IsWebSiteActive { get; set; } } public interface IConfigurationManager { Models.Configuration.Configuration ConfigFileValues { get; } }

ASP.Net MVC3 : Steven Sanderson's tutorial — using Ninject error [closed]

梦想的初衷 提交于 2019-12-13 22:35:27
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . My project errors with the global.asax Application_Start calls: ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory()); namespace SportsStore.WebUI.Infrastructure { public class

Ninject cyclic dependency - already using property injection

孤者浪人 提交于 2019-12-13 19:17:26
问题 I'm having a problem with a cyclic dependency in a project using dependency injection. In looking around, it seems that the only way to avoid it, other than restructuring (I did some of that too), is to use property injection. I tried this, and it doesn't seem to help, but I'm not sure why. Here is the path that's causing issues. Activation path: 6) Injection of dependency IUserRepository into property UserRepository of type ModelFactory{UserRole} 5) Injection of dependency IUserRoleFactory