ninject

Dependency Injection with Custom Membership Provider

坚强是说给别人听的谎言 提交于 2019-12-17 16:08:02
问题 I have an ASP.NET MVC web application that implements a custom membership provider. The custom membership provider takes a UserRepository to its constructor that provides an interface between the membership provider and NHibernate. The UserRepository is provided by the Ninject IoC container. Obviously, however, this doesn't work when the provider is instantiated by .NET: the parameterless constructor does not have a UserRepository and cannot create one (the UserRepository requires an

What is the intention of Ninject modules?

不羁的心 提交于 2019-12-17 15:35:29
问题 I'm a complete newbie to ninject I've been pulling apart someone else's code and found several instances of nInject modules - classes that derive from Ninject.Modules.Module, and have a load method that contains most of their code. These classes are called by invoking the LoadModule method of an instance of StandardKernel and passing it an instance of the module class. Maybe I'm missing something obvious here, but what is the benefit of this over just creating a plain old class and calling

How do I handle classes with static methods with Ninject?

女生的网名这么多〃 提交于 2019-12-17 12:42:55
问题 How do I handle classes with static methods with Ninject? That is, in C# one can not have static methods in an interface, and Ninject works on the basis of using interfaces? My use case is a class that I would like it to have a static method to create an unpopulated instance of itself. EDIT 1 Just to add an example in the TopologyImp class, in the GetRootNodes() method, how would I create some iNode classes to return? Would I construct these with normal code practice or would I somehow use

Binding singleton to multiple services in Ninject

╄→尐↘猪︶ㄣ 提交于 2019-12-17 11:53:08
问题 I have a problem which seems very similar to the one described in http://markmail.org/message/6rlrzkgyx3pspmnf which is about the singleton actually creating more than a single instance if you're accessing it using different service types. I'm using the latest release of Ninject 2 for Compact Framework and the exact issue I'm having is that if I bind the same provider method to: Func<Service> serviceCreator = () => new Service(false); kernel.Bind<IService>().ToMethod(serviceCreator)

Binding singleton to multiple services in Ninject

岁酱吖の 提交于 2019-12-17 11:53:07
问题 I have a problem which seems very similar to the one described in http://markmail.org/message/6rlrzkgyx3pspmnf which is about the singleton actually creating more than a single instance if you're accessing it using different service types. I'm using the latest release of Ninject 2 for Compact Framework and the exact issue I'm having is that if I bind the same provider method to: Func<Service> serviceCreator = () => new Service(false); kernel.Bind<IService>().ToMethod(serviceCreator)

How to inject UserManager & SignInManager

ⅰ亾dé卋堺 提交于 2019-12-17 10:29:13
问题 I am trying to figure out how to inject UserManager and SignInManager. I have installed Ninject in my application and I am using it in the following manner: Please consider this to be a brand new project. Inside Startup.cs I have the following: public partial class Startup { public void Configuration(IAppBuilder app) { ConfigureAuth(app); app.UseNinjectMiddleware(CreateKernel); } private static IKernel CreateKernel() { var kernel = new StandardKernel(); kernel.Load(Assembly

How to integrate Ninject into ASP.NET Core 2.0 Web applications?

[亡魂溺海] 提交于 2019-12-17 09:48:06
问题 I have found out that Ninject has recently introduced support for .NET Standard 2.0 / .NET Core 2.0. However, I cannot find any extension to actually integrate it in the Web application (e.g similar to Ninject.Web.Common) Looking on the code from an old ASP.NET MVC solution, I realized that the whole mechanism is different as the classic one relied on WebActivatorEx.PreApplicationStartMethod and WebActivatorEx.ApplicationShutdownMethodAttribute which are no longer available in ASP.NET Core.

Ninject + Bind generic repository

孤街浪徒 提交于 2019-12-17 09:37:49
问题 I'm trying to Bind a generic IRepository<> interface to my generic Repository<> - however it always return null? I have tried various things like: Bind(typeof(IRepository<CustomerModel>)).To(typeof(Repository<CustomerModel>)); Bind(typeof(IRepository<>)).To(typeof(Repository<>)); However if I pass in a non-generic interface and class then it works like a dream? 回答1: Bind(typeof(IRepository<>)).To(typeof(Repository<>)); This is the correct syntax for binding an open generic. If you are

ASP.NET MVC 4 + Ninject MVC 3 = No parameterless constructor defined for this object

折月煮酒 提交于 2019-12-17 07:14:45
问题 UPDATE - Please look at my answer for a link and explanation of the solution to this problem Before we start, I know this is a very common question and I've been using Ninject for many moons without issues, but now it's come up and I can't figure out a fix. Also, no, none of the results on Google and SO so far have helped me. So, consider the following bit of code running on a very, very, very simple prototype ASP.NET MVC 4 project from Visual Studio 2012 on Windows Server 2008 R2: public

Using HttpContext.Current in WebApi is dangerous because of async

亡梦爱人 提交于 2019-12-17 04:45:13
问题 My question is a bit related to this: WebApi equivalent for HttpContext.Items with Dependency Injection. We want to inject a class using HttpContext.Current in WebApi area using Ninject. My concern is, this could be very dangerous , as in WebApi ( everything? ) is async. Please correct me if I am wrong in these points, this is what I investigated so far: HttpContext.Current gets the current context by Thread (I looked into the implementation directly). Using HttpContext.Current inside of