ninject

How the binding are done with decorators using Ninject?

本秂侑毒 提交于 2019-11-27 14:28:11
Based on this question : Should thoses kind of service go injected in a base class ? (versus static classes) . How the binding would be done with decorators using Ninject ? or any DIContainer ? public class CachedLoggedRepository : IRepository { public IRepository repository { get; set; } void Add(); } public class CachedRepository : IRepository { public IRepository repository { get; set; } void Add(); } public class Repository : IRepository { void Add(); } Remo Gloor You have to use conditional bindings e.g Bind<IRepository>().To<Repository>().WhenInjectedInto<CachedRopsitory>(); Bind

Binding singleton to multiple services in Ninject

跟風遠走 提交于 2019-11-27 14:27:54
I have a problem which seems very similar to the one described in http://markmail.org/message/6rlrzkgyx3pspmnf which is about the singleton actually creating more than a single instance if you're accessing it using different service types. I'm using the latest release of Ninject 2 for Compact Framework and the exact issue I'm having is that if I bind the same provider method to: Func<Service> serviceCreator = () => new Service(false); kernel.Bind<IService>().ToMethod(serviceCreator).InSingletonScope(); kernel.Bind<Service>().ToMethod(serviceCreator).InSingletonScope(); It seems to be creating

MVC3 + Ninject - How to?

情到浓时终转凉″ 提交于 2019-11-27 14:22:21
I've just started playing with IoC containers and therefore chosed Ninject. After several hours of sweat and tears I still cant figure out how to setup my MVC3 application with Ninject. So far I have: Global.asax.cs public class MvcApplication : Ninject.Web.Mvc.NinjectHttpApplication { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with

Parameterless constructor error with Ninject bindings in .NET Web Api 2.1

♀尐吖头ヾ 提交于 2019-11-27 14:19:28
Working currently on writing an API site (.NET Web Api 2.1) For our prior API sites we had used the Ninject.MVC3 package and wired up a dependency resolver and scope manually and plugged in our logic into NinjectWebCommon as per the recommendation. This was causing heartburn int our new project with the parameterless constructor error. In the past, this was a dead give away that we were not wiring up the dependency resolver in Web Api properly. Only this time, we were. It was there. var resolver = new NinjectDependencyResolver(kernel); GlobalConfiguration.Configuration.DependencyResolver =

Web API2 NinjectWebCommon.cs do not appear

≡放荡痞女 提交于 2019-11-27 14:05:44
问题 I am doing an Empty Web API in Visual Studio 2013 Framework 4.5. Obviously NinjectWebCommon.cs do not appear. I installed via Nuget, Ninject, Ninject.Web.Common, Ninject.MVC5, Ninject.Web.Common.WebHost, Ninject.Web.WebApi, Ninject.web.WebApi.WebHost but NinjectWebCommon.cs still does not appear. What else do I need to install? Can I add that file manually? thanks 回答1: It looks like the most recent Ninject.Web.Common.WebHost 3.3.0 NuGet package no longer includes the NinjectWebCommon.cs.

How to bind Generic-type interfaces in Ninject

断了今生、忘了曾经 提交于 2019-11-27 13:52:44
问题 I'm fairly new to Ninject, and found myself stumbling when I came to implement a generic repository pattern. I want to bind a dependency IRepository<IEntityType> to a class ConcreteRepository<EntityType> where ConcreteRepository<T> implements IRepository<T> and EntityType implements IEntityType. I tried this: kernel.Bind<IRepository<IEntityType>>().To<ConcreteRepository<EntityType>>(); ...but Ninject won't take that because it doesn't know or care that EntityType implements IEntityType. How

Is it possible to bind different interfaces to the same instance of a class implementing all of them?

萝らか妹 提交于 2019-11-27 13:26:35
I have the following (simplified) situation: I have two interfaces interface IAmAnInterface { void DoSomething(); } and interface IAmAnInterfaceToo { void DoSomethingElse(); } and a class implementing both: class IAmAnImplementation: IAmAnInterface, IAmAnInterfaceToo { public IAmAnImplementation() { } public void DoSomething() { } public void DoSomethingElse() { } } Now I bind the same class to both interfaces using Ninject. Since I want the same instance of IAmAnImplementation beeing used for IAmAnInterface as well as IAmAnInterfaceToo it's clear that I need some kind of singleton. I played

Using Ninject WCF Extension with WCF Web Service

。_饼干妹妹 提交于 2019-11-27 13:13:08
问题 I have a WCF web service in which I want to use my Repositories and Services which I wish to dependency inject into my WCF web service, however the Ninject WCF Extension example pretty much has a ctor which is instantiating an instance of each dependency, which I don't want, I wanted a purer dependency injection. Has anyone had any success with using Ninject with WCF, Google seems to return little relevant results for the topics I am looking for. 回答1: The code behind for TimeService has: <%@

Ninject constructor injection in WPF

会有一股神秘感。 提交于 2019-11-27 12:26:25
问题 Is it possible to use ninject for dependency injection in such a way that the result would be something like the injection I can get in MVC. To elaborate, if I use the MVC ninject adapter I can declare my web controllers as having constructor parameters which would then automatically be injected by ninject. However, I haven't found such a ninject extension for WPF, which would enable me to have a window such as this: public partial class MainWindow : Window { private readonly IService

Ninject caching an injected DataContext? Lifecycle Management?

微笑、不失礼 提交于 2019-11-27 12:07:58
问题 I had a series of very bizarre errors being thrown in my repositories. Row not found or changed, 1 of 2 updates failed... Nothing made sense. It was as if my DataContext instance was being cached... Nothing made sense and I was considering a career move. I then noticed that the DataContext instance was passed in using dependency injection, using Ninject (this is the first time I have used DI...). I ripped out the Dependency Injection, and all went back to normal. Instantly. So dependency