ninject

One Controller is Sometimes Bound Twice with Ninject

守給你的承諾、 提交于 2019-12-11 03:59:10
问题 I have the following NinjectModule, where we bind our repositories and business objects: /// <summary> /// Used by Ninject to bind interface contracts to concrete types. /// </summary> public class ServiceModule : NinjectModule { /// <summary> /// Loads this instance. /// </summary> public override void Load() { //bindings here. //Bind<IMyInterface>().To<MyImplementation>(); Bind<IUserRepository>().To<SqlUserRepository>(); Bind<IHomeRepository>().To<SqlHomeRepository>(); Bind<IPhotoRepository

Service bound multiple times using ninject.extensions.conventions

我的梦境 提交于 2019-12-11 03:53:36
问题 When using ninject conventions to bind all implementations of several interfaces I got the following problem: public interface IServiceA { } public interface IServiceB { } public class Service : IServiceA, IServiceB { } public class FooA { public Foo(IEnumerable<IServiceA> a) { // a has 2 instances of Service } } public class FooB { public Foo(IEnumerable<IServiceB> b) { // b has 2 instances of Service } } // ... kernel.Bind(x => x .FromThisAssembly() .SelectAllClasses().InheritedFrom

Validation Attribute get triggered two times

我是研究僧i 提交于 2019-12-11 03:45:36
问题 In my MVC3 application I have the model ( not important properties deleted ): public class AccountViewModel { [StringLength(65)] public string Property1 { get; set; } [StringLength(65)] public string Property2 { get; set; } } The problem is when an action is submited validation attribute called twice, and I can get 4 errors in summary, instead of 2: 'Property1' length must be less than 65 characters 'Property1' length must be less than 65 characters 'Property2' length must be less than 65

Ninject: Bind multiple types to the same singleton instance

≯℡__Kan透↙ 提交于 2019-12-11 03:45:27
问题 interface IService<T> {} class ConcreteServiceA<T> : IService<T> {} I need that: IService<string> stringServices = kernel.Get<IService<string>>(); ConcreteServiceA<string> concreteStringServiceA = kernel.Get<ConcreteServiceA<string>>(); Assert.IsSameReference(stringService, concreteStringServiceA); Up to now, I've tried to create bindings: this.Bind(typeof(IService<>)) .To(typeof(ConcreteServiceA<>)) .InSingletonScope(); this.Bind(typeof(ConcreteServiceA<>)).ToSelf().InSingletonScope();

Cant find NinjectWebCommon in asp.net Web API Project

天涯浪子 提交于 2019-12-11 03:35:50
问题 I am creating an asp.net web api project. I am using Ninject for dependency resolver. I am adding Ninject.Web.WebAPI from nuget. But I don't find any NinjectWebCommon.cs in my App_Start folder Do i need to install any aditional package?? 回答1: Install Ninject.Web.WebApi.WebHost if you are hosting the WebApi project via IIS - this will create NinjectWebCommon.cs . See the wiki for more info on different types of WebApi projects. https://github.com/ninject/Ninject.Web.WebApi/wiki/Setting-up-an

Interface with multiple implementations in ninject

不问归期 提交于 2019-12-11 03:34:23
问题 I've got an interface that has two different implementations. public interface IProducer { } public class Producer : IProducer { } public class FaultProducer : IProducer { } I have two different classes that both take an IProducer as a dependency. public class ConsumerChannel { public ConsumerChannel(IProducer producer) { } } public class TradePublisher { public TradePublisher(IProducer producer) { } } TradePublisher needs a Producer and ConsumerChannel needs a FaultProducer . I can only bind

Stop Ninject from binding Func<T, T, bool> automatically

坚强是说给别人听的谎言 提交于 2019-12-11 03:24:35
问题 I have a PriorityQueue that takes a Func as construction parameter. public PriorityQueue(ISomeOtherInjectedThing other, Func<T, T, bool> cmp_func) {...} I bound this using Ninject: Bind(typeof (IPriorityQueue<,>)).To(typeof(PriorityQueue<,>)); We had a weird bug in code and as part of this, we noticed that Ninject seems to generate an object Func and injects this into our priority queue, but we don't have a binding for this. The factory should have thrown an activtion exception, since we didn

What is the equivalent code for the asp.net core DI framework from this example using Ninject?

本秂侑毒 提交于 2019-12-11 02:32:33
问题 I've been looking at using CQS pattern with EF Core within an asp.net Core web application. I found this sample, which seems to be what I want however the DI container used is Ninject. I can't seem to be able to translate the Ninject configuration into the inbuilt DI container in asp.net core. Specifically my problem is with these lines: Bind<IQueryFactory>().ToMethod(t => new QueryFactory(x => Container.Current.Resolve(x))).InTransientScope(); Bind<ICommandsFactory>() .ToMethod(t => new

Ninject is not working in custom validation attribubte in ASP.NET MVC

丶灬走出姿态 提交于 2019-12-11 01:57:26
问题 This question is the consequence of this question. I am developing an ASP.NET MVC Web Application. In my project I am doing remote validation using data annotation to my view model class. I know default remote attribute does not support server validation. I can validate it again in action method. But I do not want to do that it is violating separation of concerns. So I tried to create custom server client remote validation attribute. I found a code online and I used it. But it is giving me

How to change the scope of an existing binding in Ninject

女生的网名这么多〃 提交于 2019-12-11 01:36:50
问题 In one module, I have a binding set up for an object. There are two other modules: a testing module and a web module. The web module wants that binding to be in request scope, and the testing module wants that binding to be in singleton scope. Right now, we are just duplicating the entire binding and adding the appropriate scope. Is there a better way to do this? I am looking for a way that I can make the binding itself (it's a ToMethod binding) in the one module, and then just have the