ninject

Using ASP.NET Identity on MVC 5 project but httpcontext User.ProviderName is “AspNetSqlRoleProvider”

情到浓时终转凉″ 提交于 2020-01-11 05:45:08
问题 I have a MVC 5 project using ASP.NET Identity (Invidual user account). As Database ORM I am using Entity framework 6 and IoC is taken care by Ninject. Solution structure is following MVC project -- has my controllers, views and ninject setup. For Ninject I got Ninject.MVC3 from nuget. Data project --- has my DataContext (IdentityDbContext) and my ApplicationUser (IdentityUser). My Data services and all repositories Core project -- has all my entities and interfaces [Authorize] attribute works

Can I use Ninject to instantiate singleton services that nothing depends on?

会有一股神秘感。 提交于 2020-01-11 05:30:21
问题 I have some services in my asp.net mvc application that listen for AMQP messages and invoke methods. No controllers depend on this, so it won't get instantiated on its own. I could instantiate it manually, explicitly providing its dependencies with kernel.Get but it feels like I shouldn't have to do that. Can I make Ninject instantiate classes in singleton scope eagerly even when nothing else depends on it? 回答1: You cannot have ninject instantiate stuff in case you don't ask it to instantiate

Ninject : Resolving an object by type _and_ registration name/identifier

℡╲_俬逩灬. 提交于 2020-01-11 05:05:07
问题 I am looking for a way to do something like this with Ninject : // Sample from the Unity application block IMyService result = myContainer.Resolve<IMyService>("Data"); ( from http://msdn.microsoft.com/en-us/library/cc440957.aspx ) Is it possible? 回答1: Ninject 2.0 has this capability: Bind<IMyService>().To<MyServiceA>().Named("Data"); Bind<IMyService>().To<MyServiceB>().Named("SomethingElse"); kernel.Get<IMyService>("Data"); // will return MyServiceA 回答2: AFAIK there is no way to do that

Does anyone know of a good guide to get Ninject 2 working in ASP.NET MVC?

邮差的信 提交于 2020-01-10 19:51:37
问题 I'm struggling with the documentation to figure out exactly what I need to. The documentation (to my understanding) is for 1.5 anyway. N.B: I don't want to extend NinjectHttpApplication I've configured it to use the NinejctControllerFactory in Application_Start() but I get a null reference exception on the KernelContainer.Kernel when it tries to create a controller. Where do I configure the Kernel if I'm not extending NinjectHttpApplication? 回答1: Take a look at this blog post. It should help

How does Ninject create controller in ASP.NET MVC?

断了今生、忘了曾经 提交于 2020-01-10 18:24:46
问题 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? 回答1: 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

Replace Ninject with Simple Injector

假装没事ソ 提交于 2020-01-10 11:33:47
问题 I've used Ninject for my application. Ninject is really simple and easy to learn, but its quite slow and I try to use another IoC to compare if its faster as with Ninject. There are a lot of IoC containers for MVC3 and Simple Injector looks really good to me, but I've a lot of problems with replacting Ninject with Simple Injector. Especially with the AutoMapper . I try to convert this lines into Simple Injector code. Bind<ITypeMapFactory>().To<TypeMapFactory>(); foreach (var mapper in

Issue using ASP.Net MVC 4 Web API with Ninject.Web.WebApi

夙愿已清 提交于 2020-01-10 07:49:13
问题 I'm trying to use the new ASP.Net MVC 4 Web API project template with Ninject but have hit a wall on the following error: Method 'GetFilters' in type 'Ninject.Web.WebApi.Filter.DefaultFilterProvider' from assembly 'Ninject.Web.WebApi, Version=3.0.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7' does not have an implementation. I am creating a brand new project in Visual Studio 2010 using the ASP.Net MVC 4 -> Web API template and I am using the latest Ninject NuGet packages: Ninject 3.0

NInject with Generic interface

泄露秘密 提交于 2020-01-09 12:18:10
问题 I have defined one interface and one class: public interface IRepository<T> { } public class RoleRepository:IRepository<Domain_RoleInfo> { } Inject here: public RoleService { [Inject] public RoleService(IRepository<Domain_RoleInfo> rep) { _roleRep=rep; } } How can I perform Dependency Injection With Ninject,say how to bind? I have written a helper class as below, it works fine with non-generic interface.but how to refactor it support generic interface as above? public class

How to bind classes with required connection string in constructor using Ninject?

拜拜、爱过 提交于 2020-01-07 09:20:11
问题 How to bind classes with required connection string in constructor using Ninject? Here are the classes that I am using: AppService class: using SomeProject.LayerB; namespace SomeProject.LayerA; { public class AppService { private readonly ISomeRepository someRepository; public LocationManagementService(ISomeRepository someRepository) { this.someRepository = someRepository; } // other codes ... } } SomeRepository class: namespace SomeProject.LayerB; { public class SomeRepository :

How to inject an action into a command using Ninject?

孤人 提交于 2020-01-06 19:34:11
问题 Actually exploring the Command Pattern and finds it pretty interesting. I'm writing a WPF Windows App following the MVVM Architectural Pattern. I've begun with these post which explain the basics. Basic MVVM and ICommand usuage example Simplify Distributed System Design Using the Command Pattern, MSMQ, and .NET Now that I was able to break user actions into commands, I thought this could be great to inject the commands that I want. I noticed that the commands are found into the ViewModel in