ninject

Ninject binding with generic repository MVC returns error on Parameterless Constructor

安稳与你 提交于 2019-12-02 06:51:33
I'm trying to use a fairly simple generic repository for a number of administration lists in an application. Functionality for the admin users is just CRUD to keep the lists up to date for use elsewhere as lookups. I keep getting an error of the form: An error occurred when trying to create a controller of type 'WhatWorks.Controllers.AchievementController'. Make sure that the controller has a parameterless public constructor. I've read an awful lot of posts on SO and blogs found through Google but I can't find an answer (at least nothing that makes sense to me as an answer which may be another

Implementing OnePerSessionBehavior in NInject

╄→尐↘猪︶ㄣ 提交于 2019-12-02 06:21:01
问题 I'd like to create a OnePerSessionBehavior for NInject (v1.0) and I've mostly got it working. The only issue that remains is how to pass in fresh arguments using .WithArguments() as each new session asks for something from the container. Right now I'm keeping a reference to the container as an application variable and therefore the module only ever gets loaded one time so of course the binding only occurs once. For example, the following returns individual instances of 'Something' for each

How to inject an object into a Ninject Module

有些话、适合烂在心里 提交于 2019-12-02 06:12:44
问题 I am using Ninject for DI. I have Ninject Modules that bind some services to the Kernel and use binded object in other modules as a service. To clear the situation let's see some lines of code: This is my security module. It provides a service named PermissionManagerContainer . public class SecurityModule : NinjectModule { public override void Load() { Bind<IPermissionManagerContainer>().To<PermissionManagerContainer>().InSingletonScope(); } } At the other hand I have a FormServices module

Ninject pass constructor argument typeof class that implements the interface

妖精的绣舞 提交于 2019-12-02 02:43:56
I am attempting to use Ninject with my application logging wrapper. Here is the wrapper: public class NLogLogger : ILogger { private readonly Logger _logger; public NLogLogger(Type t) { _logger = LogManager.GetLogger(t.Name); } } As you can see I am passing the type into the loggers constrctor, so I would use it like the following: public class EntityObject { public ILogger Logger { get; set; } public EntityObject() { Logger = new NLogLogger(typeof(EntityObject)); } } Now I cannot seem to find out how to do something similar with using Ninject. Here is my binding module: public class

How to inject an object into a Ninject Module

瘦欲@ 提交于 2019-12-02 02:02:55
I am using Ninject for DI. I have Ninject Modules that bind some services to the Kernel and use binded object in other modules as a service. To clear the situation let's see some lines of code: This is my security module. It provides a service named PermissionManagerContainer . public class SecurityModule : NinjectModule { public override void Load() { Bind<IPermissionManagerContainer>().To<PermissionManagerContainer>().InSingletonScope(); } } At the other hand I have a FormServices module that should add an item to the injected PermissionManagerContainer . I think the code must be something

How to inject ModelState as parameter with Ninject?

雨燕双飞 提交于 2019-12-02 01:58:03
Im very new to Ninject. I want to find a way to pass Modelstate of a controller further to service layer. what i have right now: private readonly IAccountService service; public AccountController(ILanguageService ls, ISessionHelper sh) { this.service = new AccountService(new ModelStateWrapper(this.ModelState)); this.languageService = ls; this.sessionHelper = sh; } public AccountService(IValidationDictionary validationDictionary) { this.validationDictionary = validationDictionary; } want i want to get to in some way: private readonly IAccountService service; public AccountController

Ninject with MVC3 RTM

笑着哭i 提交于 2019-12-02 01:25:10
I've upgraded MVC3 from RC2 to RTM. We were using Ninject 2.1.0.76, but things stopped working once I upgraded. So I used the NuGet manager to get the latest Ninject, Ninject.MVC3 and Ninject.Web.Mvc libraries (2.1.0.91, 1.0.0.0 and 2.1.0.39 respectively). Now, it creates an AppStart_NinjectMVC3 file. I removed NinjectHttpApplication from my global.asax and made it back into a regular HttpApplication. When I tried to build, I get; "Exception has been thrown by the target of an invocation" Looking further, if I disable the following line; DependencyResolver.SetResolver(new NinjectServiceLocator

Implementing OnePerSessionBehavior in NInject

爱⌒轻易说出口 提交于 2019-12-01 23:23:38
I'd like to create a OnePerSessionBehavior for NInject (v1.0) and I've mostly got it working. The only issue that remains is how to pass in fresh arguments using .WithArguments() as each new session asks for something from the container. Right now I'm keeping a reference to the container as an application variable and therefore the module only ever gets loaded one time so of course the binding only occurs once. For example, the following returns individual instances of 'Something' for each new session, but the constructor argument passed in to all sessions is the same DateTime. Bind<ISomething

Referencing Ninject in class library in ASP.NET MVC 3 application

邮差的信 提交于 2019-12-01 20:20:31
问题 I have an ASP.NET MVC 3 application that uses the Ninject.MVC3 extension to setup DI in my MVC application. Namely, there's the NinjectMVC3.cs file in the App_Start folder where my bindings are defined. This works well for DI into my application's controllers. In addition to the ASP.NET MVC web application, my Solution also contains a class library projects, let's call it MyProject.Core , which has my domain model, services, and so on. In there I have a class called UserServices that uses a

How to use Ninject to inject services into MVC 3 FilterAttributes?

点点圈 提交于 2019-12-01 19:28:24
I'm writing a custom ErrorHandler attribute for my MVC project. I would like to inject an implementation of EventViewerLogger into that attribute. I'm using Ninject 2.2 and it works fine for other features, such as injection repositories and aggregate services through controller constructors. I understand that I can't inject an implementation of some class into attribute through constructor, therefore I have to inject it into the attribute's property. Interface is below: namespace Foo.WebUI.Infrastructure { public interface ILogger { void Log(Exception e); } } Event viewer logger