ninject

Getting 'Context is not constructible. Add a default constructor or provide an implementation of IDbContextFactory."

末鹿安然 提交于 2019-12-18 07:34:20
问题 I am getting this error when I try to use code first migrations. My context has a constructor with the connection name. public class VeraContext : DbContext, IDbContext { public VeraContext(string NameOrConnectionStringName = "VeraDB") : base(NameOrConnectionStringName) { } public IDbSet<User> Users { get; set; } public IDbSet<Product> Products { get; set; } public IDbSet<IntCat> IntCats { get; set; } } This connection name is injected with ninject when the project runs, I have also specified

How to implement an [GoF]-ish Abstract Factory Pattern using an IoC like Ninject

时光总嘲笑我的痴心妄想 提交于 2019-12-18 07:06:32
问题 Abstract When the design requires an "Abstract Factory Pattern" like stated by the [GoF] including several products and over some product families, then setting up an IoC can become a bit tricky. Especially when the specific factory implementations need to be dispatched by runtime parameters and shared among some subsequent components. Given the follwing API, i was trying to set up my IoC (Ninject in this case) to retrieve Configuration objects configured through a IConfigurationFactory . The

How to use Ninject Conventions extension without referencing Assembly (or Types within it)

痞子三分冷 提交于 2019-12-18 05:36:30
问题 Sorry in advance for the long question, it's long because I've been digging at this all day. The general problem: I have an ASP.Net MVC2 application with the following projects: MyApp.Web, MyApp.Services, MyApp.Data. We code to interfaces and utilize Ninject 2 for DI/IoC. However, I'm getting awfully tired of typing (and forgetting to type): Bind<ISomeService>.To<SomeService>; So, knowing about Ninject.Extensions.Convensions, I have attempted to use it to automatically scan and register

Upgrading Ninject/Ninject WCF Extensions to the latest version 3.0.0.5

孤街醉人 提交于 2019-12-18 04:46:11
问题 I am currently using Ninject (2.2.1.4) and Ninject.Extensions.Wcf (2.2.0.4) with my WCF service. I would like to upgrade to Ninject (3.0.0.15) and Ninject.Extensions.Wcf (3.0.0.5) and it doesn't look like I can use my current approach anymore. Can anyone point me to some samples or posts on how to get the latest version of Ninject working with a WCF project. My current approach: I wrote a module: public class NinjectDependencyResolver : NinjectModule { public override void Load() { // Declare

Ninject default contextual binding

旧巷老猫 提交于 2019-12-18 03:57:06
问题 I have an interface with a few different concrete implementations. I am trying to give Ninject a default to use and only use the other implementation if a name matches. For instance, I have the following bindings. Bind<ISomething>().To<DefaultSomething>() Bind<ISomething>().To<OtherSomething>().Named("55abd8b8-097f-4e1c-8d32-95cc97910604"); What I would like is if the Named section doesn't match, to use the DefaultSomething implementation. When I pass in the explicitly bound guid, it works

Combining DI with constructor parameters?

五迷三道 提交于 2019-12-17 22:35:04
问题 How do I combine constructor injection with "manual" constructor parameters? ie. public class SomeObject { public SomeObject(IService service, float someValue) { } } Where IService should be resolved/injected by my DI container, and someValue should be specified. How do I mix the two? 回答1: Such constructs should be avoided whenever possible. Therefore, ask yourself: is this parameter really required as constructor argument? Or can SomeObject be replaced by a stateless one which is reused by

NinjectDependencyResolver fails binding ModelValidatorProvider

江枫思渺然 提交于 2019-12-17 18:16:22
问题 I'm developing an ASP.NET Web Api 2.2 with C#, .NET Framework 4.5.1. After updating my Web.Api to Ninject 3.2.0 I get this error: Error activating ModelValidatorProvider using binding from ModelValidatorProvider to NinjectDefaultModelValidatorProvider A cyclical dependency was detected between the constructors of two services. Activation path: 3) Injection of dependency ModelValidatorProvider into parameter defaultModelValidatorProviders of constructor of type DefaultModelValidatorProviders 2

Ninject in .NET Core

扶醉桌前 提交于 2019-12-17 16:33:52
问题 I am trying to install Ninject 3.3.2 in .NET Core, Released in May 2016. I got an error: The dependency Ninject 3.2.2 does not support framework .NETCoreApp, Version=v1.0. Does anybody had similar problem, and is there any solution for this? 回答1: Ninject does not support .NET Core. You can check it's website to be sure if there is no version that supports it. ASP.NET Core has its own Dependency Injection container build in. See here. 回答2: Ninject 3.3.0 was released September 26th 2017 and now

I'm confused about interface abstractions when using IoC

让人想犯罪 __ 提交于 2019-12-17 16:28:12
问题 I've recently been trying to learn IoC, and have a couple questions based on the following code: public class WarriorModule : NinjectModule { public override void Load() { Bind<IWeapon>().To<Sword>(); Bind<Samurai>().ToSelf(); } } I'm having trouble grasping the new concept of interfaces. Before I would create an interface such as IRunnable , implementing the function void Run() . With IoC, I'm now viewing an interface as something that only maps to a single concrete class. Assuming that, how

Run unit tests in different appdomain with NUnit

老子叫甜甜 提交于 2019-12-17 16:22:28
问题 I seem to be having an issue, the application we're using uses a Ninject kernel, and contains a particular configuration that's gathered with contents of the WCF call (username, token...). Based on that a particular configuration the user is assigned rights on the app, this is shielded through a particular instance in the Ninject kernel. We cannot just recompose the Ninject kernel, what we'd like to do is run a couple of Nunit tests, but run each of them in a separate app domain (recreating