ninject

' Sequence contains no elements' exception when initializing ninject

非 Y 不嫁゛ 提交于 2019-12-10 12:39:57
问题 I have a problem with Ninject which I have not seen before and don't know how to fix. I am using the MVC NuGet package for MVC 5. In my NinjectWebCommon.cs, there is the following method: public static void Start() { DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule)); DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule)); bootstrapper.Initialize(CreateKernel); } However, it falls over when trying to execute the last line, complaining that the "sequence contains no

Ninject giving NullReferenceException

被刻印的时光 ゝ 提交于 2019-12-10 11:27:43
问题 I'm using asp.net MVC 2 and Ninject 2. The setup is very simple. Controller calls service that calls repository. In my controller I use inject to instantiate the service classes with no problem. But the service classes don't instantiate the repositories, giving me NullReferenceException. public class BaseController : Controller { [Inject] public IRoundService roundService { get; set; } } This works. But then this does not... public class BaseService { [Inject] public IRoundRepository

How to pass parameters down the dependency chain using Ninject

空扰寡人 提交于 2019-12-10 11:26:57
问题 My Class Structure is: public class PhotoService { private IRepository _repo; private DTConfig _config; public PhotoService(IRepository repo, DTConfig config) { _repo = repo; _config = config; } } public class DTConfig { private int _accountId; public DTConfig(int accountId) { _accountId = accountId; } } My Ninject Bindings are like: var kernel = new StandardKernel(); kernel.Bind<IPhotoService>().To<PhotoService>(); kernel.Bind<IRepository>().To<Repository>(); kernel.Bind<DTConfig>().ToSelf()

No parameterless constructor object defined

大城市里の小女人 提交于 2019-12-10 10:03:50
问题 I know that this is a duplicate question but i can't find answer to my error. I'm trying to show a list of my rooms saved in database but i get next error: Server Error in '/' Application. No parameterless constructor defined for this object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.MissingMethodException: No

Ninject conditional binding

↘锁芯ラ 提交于 2019-12-10 07:59:50
问题 I'm playing around with Ninject for a simple test-bed project at home, just to see what I can do with it. As a starting point I'm building a console runner for some service, which accepts a variety of arguments and based on what it gets in, uses the same methods provided for a fluent interface to configure a model to run. As an example, suppose I have a verbosity switch, /o . /o can be passed as /o:quiet , /o:normal , or /o:verbose . The various options are self-explanatory. To satisfy this

How do I Inject Dependencies with Ninject, where instances are deserialised from json

点点圈 提交于 2019-12-10 07:53:06
问题 This is my first try using DI, I've chosen ninject for it's reportedly easy learning curve, and have this question. I'm creating objects like this: var registrants = JsonConvert.DeserializeObject<List<Registrant>>(input); I currently have this constructor for Registrant [Inject] public Registrant(IMemberRepository memberRepository) { _memberRepository = memberRepository; } What is the best way to have the repository dependency be injected into the deserialized object(s) using Ninject? 回答1:

Using Ninject DI for both api and “regular” controllers in MVC4 [duplicate]

核能气质少年 提交于 2019-12-10 06:10:01
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: MVC3 + Ninject - How to? In a small mvc 4 project, I'm trying to implement dependency injection using ninject. So far, I have it working with api controllers, but I'm not having any luck with regular controllers. I have A NinjectResolver: public class NinjectDependencyResolver : NinjectDependencyScope, IDependencyResolver { private readonly IKernel _kernel; public NinjectDependencyResolver(IKernel kernel) :

Injecting an IEnumerable into a constructor with a Ninject factory method

巧了我就是萌 提交于 2019-12-10 03:14:55
问题 I'm trying to inject an IEnumerable into a constructor with Ninject. My constructor looks like this: public MatrixViewModel(IEnumerable<FooViewModel> fooViewModels) { _fooViewModels = fooViewModels; } My Ninject module looks like this: public class MainModule : NinjectModule { public override void Load() { Bind<IEnumerable<FooViewModel>>() .ToMethod(context => GetFooViewModels()) .InSingletonScope(); // this binding is not working } private IEnumerable<FooViewModel> GetFooViewModels() { //

How do i use Ninject 2 in an ASP.NET MVC 3 application?

两盒软妹~` 提交于 2019-12-09 23:59:39
问题 Ive searched everywhere, i can't seem to find a way to implement ninject in my project. Ive heard of deriving MvcApplication to the NinjectHttpApplication. But NinjectHttpApplication isnt found even if i add the lib to the reference. I can't find Ninject.Web.Mvc. Does anyone have a guide somewhere in order to make this work, all i want to do is be able to bind my interface from my domain to existing implementation. 回答1: http://weblogs.asp.net/shijuvarghese/archive/2010/04/30/dependency

Problem with Ninject and MVC3 Dependency injection action filter on Controller and Action

我是研究僧i 提交于 2019-12-09 19:00:42
问题 Recently I decided to remove a heap of action level filters in a controller and replace them with a single controller level filter. Now I'm getting this error message. Error activating LogActionFilter More than one matching bindings are available. Activation path: 1) Request for LogActionFilter Suggestions: 1) Ensure that you have defined a binding for LogActionFilter only once. I'm sure the error is related to action filter being bound twice, as that's what I've changed. However, when I view