ninject

Parameterized Factories Using Ninject

风流意气都作罢 提交于 2019-12-04 15:59:23
问题 How to make Ninject to instantiate object based on variable on run time?. I am trying to inject the correct Repository in The Controller action - MVC 3 - based on parameter come from user input. If user input "BMW" it would bind ICarRepository to BMWRepository , and if he input "KIA" KiaRepository will be injected. [HttpPost] public ActionResult SearchResult(FormCollection values) { string carModel = values["model"]; ICarRepository myRepository = RepositoryFactory.getRepository(carModel); ...

Ninject.MVC5 not generating NinjectWebCommon.Cs

那年仲夏 提交于 2019-12-04 15:51:20
问题 I'm developing a MVC5 project on Visual Studio 2017 Version 15.4. I'm getting unexpected result here what I never faced before. I've installed Ninject.MVC5 package from nuget . It's installing nicely and not giving any error or warning. But problem is it's not generating NinjectWebCommon.cs file in App_Start folder. Is there any reason? 回答1: It looks like the most recent Ninject.Web.Common.WebHost 3.3.0 NuGet package no longer includes the NinjectWebCommon.cs. Older versions, such as 3.2.0 do

Ninject WithConstructorArgument : No matching bindings are available, and the type is not self-bindable

瘦欲@ 提交于 2019-12-04 15:47:05
问题 My understanding of WithConstructorArgument is probably erroneous, because the following is not working: I have a service, lets call it MyService, whose constructor is taking multiple objects, and a string parameter called testEmail. For this string parameter, I added the following Ninject binding: string testEmail = "test@example.com"; kernel.Bind<IMyService>().To<MyService>().WithConstructorArgument("testEmail", testEmail); However, when executing the following line of code, I get an

Learning Inversion of Control through Dependency Injection in MVC 3

巧了我就是萌 提交于 2019-12-04 15:45:15
Can someone please provide me a simple example of DI and IoC ? I understand the first one but was unable to get an implementation of the second one. I'm working with MVC 3 and I really want to use the IDependencyResolver , but I can't understand how. Is ninject an option or is it required? Is there a tutorial like nerdDinner and I wasn't able to find it? Can somebody give me a link to study it? Ruben Bartelink In order to grok real world DI and its patterns and anti-patterns quickly, I recommend getting DI in .NET . (I've ordered it already EDIT: And it was a page turner that taught me a lot

HttpConfiguration.get_ServiceResolver() Missing

喜欢而已 提交于 2019-12-04 15:01:54
I am wiring up Ninject with MVC4 and have it working to the point it's trying to actually resolve dependencies. However, I am getting the following exception: Method not found: 'System.Web.Http.Services.DependencyResolver System.Web.Http.HttpConfiguration.get_ServiceResolver()'. Anyone ran into this and have a work around? GlobalConfiguration.Configuration.ServiceResolver was replaced with GlobalConfiguration.Configuration.DependencyResolver in the RC. So I guess the Ninject package you are using is simply not designed for the RC. It was one of the breaking changes. So here are the steps to

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

天涯浪子 提交于 2019-12-04 14:21:52
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 the documentation here I can see it specifies/does the same. So I'm really not sure what I'm doing

Selective validation of child properties - Fluent Validation in MVC

拟墨画扇 提交于 2019-12-04 14:03:29
问题 I'm using Fluent Validation with the Ninject.Web.Mvc.FluentValidation library to automatically wire up all of my validators (and use dependency injection to create the validators). I created the following Models: public class Parent { public string Name { get; set; } public Child Child1 { get; set; } public Child Child2 { get; set; } } public class Child { public string ChildProperty { get; set; } } With the following validators: public class ParentValidator : AbstractValidator<Parent> {

ASP.NET MVC 3 and Global Filter Injection

二次信任 提交于 2019-12-04 13:43:42
问题 Hello am an trying to implement a global filter with injection. The filter looks like this. public class WikiFilter : IActionFilter { private IWikiService service; public WikiFilter(IWikiService service) { this.service = service; } public void OnActionExecuting(ActionExecutingContext filterContext) { !!!Code here!! } public void OnActionExecuted(ActionExecutedContext filterContext) { throw new NotImplementedException(); } } And i have attached the filter with injection the following way in my

Ninject: Is it possible to have parent object in SingletonScope and child in TransientScope?

故事扮演 提交于 2019-12-04 13:10:27
I have been racking my brain on and off with this for a few weeks now... What I currenlty have is this: A bunch of *Service classes All of these depend on different *Repository classes that access database via EF To allow Unit Testing a derivate of DbContext is injected into repositories. (so I can not use using to dispose of the contexts) To correctly dispose of the EF contexts that are injected I could run my dependency tree in InRequestScope() or in a simple custom scope - InScope(c => new object()) on the top level and in InParentScope() on all other levels. Both of these approaches would

Using Ninject 2.0 with ASP .Net 3.5

╄→尐↘猪︶ㄣ 提交于 2019-12-04 13:07:12
I am trying to use Ninject 2.0 with Asp .Net 3.5 web application. Following are the DLLS and it's versions I am using. Ninject.dll - v2.0.0.0 Ninject.Extensions.Logging.dll v2.0.0.0 Ninject.Web.dll v1.0.0.0 In my global.ascx.cs I have following method. protected override IKernel CreateKernel() { IKernel kernel = new StandardKernel(); kernel.Bind<IDataAccess>().To<DataAccessEntBlock>().InSingletonScope(); return kernel; } When I run the application I get following error. Error activating ILoggerFactory No matching bindings are available, and the type is not self-bindable. Activation path: 1)