ninject

WCF using Ninject Dispose not triggering in requestscope

房东的猫 提交于 2019-12-08 18:46:46
问题 Here is my module internal class WebServiceConfiguration : NinjectModule { public override void Load() { Bind<IWebService>().To<WebService>().InRequestScope(); } } Here is the global.asax public class Global : NinjectHttpApplication { protected override IKernel CreateKernel() { return new StandardKernel(new WebServiceConfiguration()); } } I also tried InScope(c => OperationContext.Current) Here is my service with IDisposable in IWebService [ServiceBehavior(InstanceContextMode =

Ninject 2.1 ActivationException : Error activating string

我的未来我决定 提交于 2019-12-08 18:29:03
问题 I am confused about why I am receiving "Ninject.ActivationException : Error Activating string No matching bindings are available, and the type is not self-bindable" in random bindings. If I leave the binding for IMedia in place it will throw the ActivationException, but if I use the CallbackProvider it works. All of these classes are structured the same with a few different properties. I'm confused as to why ILocationType, IMedia, and IFarmDataContext throw ActivationException while the

Is property injection considered to be bad?

强颜欢笑 提交于 2019-12-08 17:28:38
问题 Example solution to demonstrate the problem: class World { public override string ToString() { return "Hello World"; } } class Hello { [Inject] public World theWorld { get; set; } public Hello(IKernel kernel) { kernel.Inject(this); } public override string ToString() { return theWorld.ToString(); } } class Program { static IKernel kernel = new StandardKernel(); static void RegisterServices() { kernel.Bind<World>().ToSelf(); } static void Main(string[] args) { RegisterServices(); Hello hello =

Ninject tutorials/documentations?

China☆狼群 提交于 2019-12-08 17:20:47
问题 According to the official site: The best place to learn about Ninject is from the official wiki on Github. Is that true? As a beginner, I found the official wiki not very helpful. Are there any better tutorials available? I tried Google, but didn't find what I was looking for. 回答1: Depends on what context you're using it - e.g. for ASP.NET Web Forms and ASP.NET MVC there are a good few blog posts around (though the Web Forms are typically based on v1) I personally found that I just wanted a

Still need help understanding why Ninject might be better than manual DI

旧街凉风 提交于 2019-12-08 17:00:38
问题 This is an extension to the question Why do I need an IoC container as opposed to straightforward DI code? I've been learning Ninject and came up with the following example, the example goes through the manual way of doing DI and the Ninject way of doing DI: class Program { static void Main(string[] args) { NinjectWay(); ManualWay(); Console.ReadKey(); } private static void ManualWay() { Console.WriteLine("ManualWay***********************"); IWeapon sword = new Sword(); Samurai samurai = new

Ninject Web Api “Make sure that the controller has a parameterless public constructor.”

雨燕双飞 提交于 2019-12-08 09:50:23
问题 I've been using ninject for almost 2 years but now when using it my ASP.NET MVC/WebAPI project i get this message and the previous threads on stackoverflow with various suggestions hasn't solved my problem. I have the follow nuget packages: Ninject MVC3 Ninject Integration for WebApi 2. I've tried solving the problem for longer that I'd like too and would really appreciate any help and suggestions that i could get! (Id gladly put the solution on Github if someone want to take a closer look)

How to organize DI Framework usage in an application?

风格不统一 提交于 2019-12-08 09:31:33
问题 EDIT: I forgot to move the kernel into a non-generic parent class here and supply a virtual method to access it. I do realize that the example below, as is, would create a plethora of kernel instances. I just learned how to do injection this past week and here's how I've got things set up currently: using Ninject; using System.Reflection; namespace Infrastructure { public static class Inject<T> { static bool b = Bootstrap(); static IKernel kernel; static bool Bootstrap() { kernel = new

Injection of class with multiple constructors

你说的曾经没有我的故事 提交于 2019-12-08 07:22:27
问题 Resolving a class that has multiple constructors with NInject doesn't seem to work. public class Class1 : IClass { public Class1(int param) {...} public Class1(int param2, string param3) { .. } } the following doesn’t seem to work: IClass1 instance = IocContainer.Get<IClass>(With.Parameters.ConstructorArgument(“param”, 1)); The hook in the module is simple, and worked before I added the extra constructor: Bind().To(); 回答1: The reason that it doesn't work is that manually supplied .ctor

Simple Injector FilterInjection seems to be reinitialising RegisterPerWebRequest injected item

邮差的信 提交于 2019-12-08 06:39:56
问题 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

Ninject Singleton for MVC Data Repository

Deadly 提交于 2019-12-08 06:24:26
问题 In my MVC3 app I have an IDataRepository interface which is referenced by all my controllers to give them access to the data layer. There's also a DataRepository class which is implements IDataRepository for a particular data source (an nHydrate-derived Entity Framework, in my case). The DataRepository class takes a single argument, which is the connection string to the underlying database. I've been successfully using nInject to to IoC with the controller classes using the following binding: