ninject

Ninject - How to dynamically select an implementation to bind to an interface

此生再无相见时 提交于 2019-12-12 15:05:27
问题 I'm currently using Ninject to create instances of interfaces in a WCF Services application. Bind<IObjA>().To<ObjA>().InRequestScope(); Bind<IObjB>().To<ObjB>().InRequestScope(); Bind<IObjC>().To<ObjC>().InRequestScope(); It works great, but we are going to have several implementations of IObjC. What options do I have for continuing fluid assignment of implementation to interface for IObjA/IObjB but allowing for configurable assignment for IObjC? I found a related question on SO but I don't

Ninject and trust level medium

亡梦爱人 提交于 2019-12-12 15:02:35
问题 I am trying to host my asp.net mvc 4 web app using hostgator. The problem at hand is the fact that the plan I am using only allows for the medium trust level. My application currently has the Ninject MVC package installed. I have tried using the ".NET Framework 4.0 for medium trust environments" version of Ninject from Ninject's homepage, but alas no go. Is there any way I can get Ninject 3.0 working with a medium trust level? The application attempted to perform an operation not allowed by

Slow loading first page - ASP.NET MVC

こ雲淡風輕ζ 提交于 2019-12-12 14:40:36
问题 I used miniprofiler for my page because I think I have big loading time for my first page and some other pages. I am starting with miniprofiler but I think it is very good tool. I have this result: http://localhost:50783/ 192.2 +0.0 Getting articles from database 2.2 +186.9 Find: Index 866.4 +190.9 Render : Index 1839.0 +1058.1 Find: _Article 530.0 +2809.0 Render partial: _Article 64.3 +3339.2 Render partial: _Article 8.2 +3404.2 Render partial: _Article 12.5 +3413.0 Render partial: _Article

Ninject: auto mocking using NSubstitute?

梦想与她 提交于 2019-12-12 14:14:27
问题 Can anyone help, I am having problems using the auto-mocking that is available between Ninject and NSubstitute, actually the package is a ninject packaged called Ninject.MockingKernel.NSubstitute which should allow me to use Ninject to create mocks and return instances with mocks injected. There seems to be a few examples for Moq and Rhinomocks but I don't see any for NSubstitute. What I have so far is this.kernel = new NSubstituteMockingKernel(); var summaryService = this.kernel.GetMock

Ninject Binding by Convention not working with generics types

纵饮孤独 提交于 2019-12-12 14:11:52
问题 I am using .NET 4.5, Ninject 3 with the binding by convention lib as follow: kernel.Bind(x => x .FromAssembliesMatching("assembly.dll") .SelectAllClasses().InheritedFrom(typeof(ICommandHandler<>)) .BindAllInterfaces()); And this is binding properly for: public class MyCommandHandler : ICommandHandler<MyCommand> But doesn't bind: public class MyGenericCommandHandler<T> : ICommandHandler<MyGenericCommand<T>> However, the previous binding works if I add individual bindings for specific

Is it mandatory for DbContext to be injected .InPerRequestScope in ASP.NET application?

*爱你&永不变心* 提交于 2019-12-12 13:25:25
问题 I have been using Ninject IoC container in my ASP.NET MVC3 portal. Whenever I've been injecting Entity Framework DbContext in PerThread scope, my data wasn't consistent, changes would not get displayd for some time after I've made changes to Entities, etc. After I've switched the IoC configuration to resolve a fresh copy of my DbContext instance for each request ( PerRequestScope() ), all the problems were gone. So is it absolutely mandatory to use PerRequest injection strategy in MVC3

Issues after installing ninject mvc 3 in mvc 5 project

元气小坏坏 提交于 2019-12-12 13:19:22
问题 I have created new asp mvc 5 project. Project target .NET 4.5. I installed ninject mvc 3 nuget package. But when I run project I get this error in NinjectWebCommon.cs in CreateKernel() method: An exception of type 'System.IO.FileLoadException' occurred in Ninject.dll but was not handled in user code Additional information: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's

using ninject to inject dependency to The Model classes or non-controller classes

这一生的挚爱 提交于 2019-12-12 13:16:07
问题 I using Ninject 3 in Repository pattern in mvc 3 (steven sanderson Scaffolder). and in ninject i have the class "NinjectWebCommon" which in the "RegisterServices" method i resolved the dependencies and i think im ready to go. private static void RegisterServices(IKernel kernel) { kernel.Bind<ICityRepository>().To<CityRepository>(); kernel.Bind<IVillageRepository >().To<VillageRepository>(); } i using my repositories in controllers using constructor injection and everything is fine. public

How to tell Ninject to inject the same instance for nested constructors?

て烟熏妆下的殇ゞ 提交于 2019-12-12 11:31:53
问题 I have a Windows Service application, where I would like to use Ninject for my service classes. There are some service classes which use other, let's say "lower level", or more generic service classes. Each service usually needs a repository for data access. So for example I have an IRepository interface, an IServices1 and an IServices2 interface. There are Services1 and Services2 implementations of the latter two, both having a constructor parameter of type IRepository. Now assume that

C# method that is executed after assembly is loaded

元气小坏坏 提交于 2019-12-12 11:14:40
问题 I write some C# class libary and I want to use Ninject to provide dependency injection for my classes. Is it possible for class libary to declare some code (method) that would be executed each fime the class libary is loaded. I need this to define bindings for Ninject. 回答1: I have used Ninject quite a bit over the last 9 months. Sounds like what you need to do is "load" your modules that exist in your libray into the Ninject kernel in order to register the bindings. I am not sure if you're