ninject.web.mvc

How to inject User Manager to Account Controller with default Identity Model in Identity 2 using Ninject

末鹿安然 提交于 2019-12-02 05:54:00
问题 I use Ninject on a MVC 5 project with Identity 2. For rest of data context and controllers using that I have no problems with dependency injection. For Account controller that uses Identity 2 model I'm getting null UserManager when I try to login: public class AccountController : Controller { private ApplicationUserManager _userManager; public AccountController() { } public AccountController(ApplicationUserManager userManager) { UserManager = userManager; } public ApplicationUserManager

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 “No parameterless constructor defined for this object.”

半腔热情 提交于 2019-12-01 18:20:45
I'm testing Ninject, but following the how-to, i find it impossible to make it work. The information on the web is so messy even contradictory. I'm developping a website in MVC 4 on visual studio 2012 and i did install Ninject using Nuget. So I get an error : "No parameterless constructor defined for this object.". As soon as I enter my controller. I did the necessary steps : Nuget installation in NinjectWebCommon.cs, I did register my Interface in the RegisterServices method. In my homecontroller I set my object like this : public ISurvey _survey { get; set; } [Inject] public HomeController

FileLoadException after installing Ninject.MVC5

若如初见. 提交于 2019-12-01 08:15:46
I am trying to learn ASP.NET MVC with Adam Freeman's "Pro ASP.NET MVC 5" book. Unfortunately all projects using Ninject throw the same error 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 manifest definition does not match the assembly >reference. (Exception from HRESULT: 0x80131040) This is exactly the same problem which was discussed in this

FileLoadException after installing Ninject.MVC5

独自空忆成欢 提交于 2019-12-01 06:39:13
问题 I am trying to learn ASP.NET MVC with Adam Freeman's "Pro ASP.NET MVC 5" book. Unfortunately all projects using Ninject throw the same error 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 manifest definition does not match the assembly

How to stop Ninject from overriding custom DataAnnotationsModelValidatorProvider?

∥☆過路亽.° 提交于 2019-12-01 01:56:18
问题 I have a custom DataAnnotationsModelValidatorProvider for doing model validation in a more dynamic way then just adding attributes. I tried to add my provide to the global.asax.cs like so: ModelValidatorProviders.Providers.Clear(); ModelValidatorProviders.Providers.Add(new AttributeValidatorProvider()); But once I load my form, I get an error saying "Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required".

Ninject - dynamically specifying a connection string based on a sub domain

怎甘沉沦 提交于 2019-11-30 23:49:27
I'm trying to specify a connection string dynamically based of the url using ninject. I'm using the ninject.mvc nuget package that uses the webActivator. My code is as follows: my injection: kernel.Bind<IUnitOfWork>().To<UnitOfWork>() .WithConstructorArgument("connectionString", MvcApplication.GetConnectionStringName()); my global.asax private static HttpContext _context; public static string GetConnectionStringName() { var subDomain = String.Empty; if (_context != null) { subDomain = _context.Request.Url.SubDomain(); } return String.Format("{0}ConnectionString", subDomain); } The problem is

Inject dependency into DelegatingHandler

余生颓废 提交于 2019-11-30 20:43:30
I am new to dependency injection, but happy with Ninject and Ninject.Extensions.Logging to [Inject] my ILogger wherever i need it. However some DelegatingHandlers are spoiling all the fun. public class HttpsHandler : DelegatingHandler { [Inject] public ILogger Logger { get; set; } protected override Task<HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken cancellationToken) { if (!string.Equals(request.RequestUri.Scheme, "https", StringComparison.OrdinalIgnoreCase)) { Logger.Info(String.Format("{0}: is using HTTP", request.RemoteAddress()); return Task.Factory

Do I need to register Ninject.OnePerRequestModule with Ninject.Web.MVC 3.0?

北城余情 提交于 2019-11-30 19:22:24
I'm using Ninject for DI and the Ninject.MVC3 extension within an MVC4 app, specifically version 3.0.0.6. Reading the documentation on Ninject's wiki, it appears that the lifetime of objects created with InRequestScope are actually controlled by ASP.NET and to properly clean up one should register the OnePerRequest HttpModule. However it looks like this doco is out of date as type="Ninject.OnePerRequestModule"/> cannot be found. On the other hand I read some bits recently that seemed to suggest that NinjectHttpApplication already deals with OnePerRequest . My question is whether Ninject.Web

How does Ninject create controller in ASP.NET MVC?

时光总嘲笑我的痴心妄想 提交于 2019-11-30 12:14:56
This may be stupid question, but I am looking at Ninject sources and don't see NInject registering its own controller factory. I also don't see any IControllerFactory class in Ninject.Web.Mvc assembly. Am I missing something? How does Ninject create controller and inject parameters into constructor? Lets say we are looking for "/Task/Index". Ninject MVC applications use now DefaultControllerFactory , the same as non-Ninject applications. DefaultControllerFactory finds type for controller ( TaskController ). DefaultControllerFactory has internal class called DefaultControllerActivator .