ninject

Ninject in .NET Core

喜欢而已 提交于 2019-11-27 23:35:11
I am trying to install Ninject 3.3.2 in .NET Core, Released in May 2016. I got an error: The dependency Ninject 3.2.2 does not support framework .NETCoreApp, Version=v1.0. Does anybody had similar problem, and is there any solution for this? Daniel Krawieczyński Ninject does not support .NET Core. You can check it's website to be sure if there is no version that supports it. ASP.NET Core has its own Dependency Injection container build in. See here . Ninject 3.3.0 was released September 26th 2017 and now targets .NET Standard 2.0 and thus also runs on .NET Core 2.0 . From the course of things

Ninject to bind on different controllers

半城伤御伤魂 提交于 2019-11-27 23:16:26
I am trying to Bind two concrete classes to one interface. What command should I use in Ninject to do that? What I am trying to do is to Bind two concrete classes to one interface base on the controller Name. Is that possible? I suppose that in ninject you use the .When to give the conditional but there is no tutorial out there where they show you how to use the .When for ninject. Here are few examples. Check out Ninject source project and its Tests subproject for various samples of usage, that's the best documentation for it, especially since docs haven't been updated for v2 yet. // usage of

MVC3, Ninject and Ninject.MVC3 problem

喜夏-厌秋 提交于 2019-11-27 22:48:27
问题 I just start using Ninject with MVC3 so here is my problem: - I installed Ninject 2.2.1.4 and Ninject.MVC3 2.2.2.0 from Nuget - In my WebUI (MVC3 project): Global.asax.cs public class MvcApplication : NinjectHttpApplication { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "

Run unit tests in different appdomain with NUnit

风格不统一 提交于 2019-11-27 22:19:57
I seem to be having an issue, the application we're using uses a Ninject kernel, and contains a particular configuration that's gathered with contents of the WCF call (username, token...). Based on that a particular configuration the user is assigned rights on the app, this is shielded through a particular instance in the Ninject kernel. We cannot just recompose the Ninject kernel, what we'd like to do is run a couple of Nunit tests, but run each of them in a separate app domain (recreating the kernel each time with different settings). I've only found ways to run whole test projects in

how to inject quartz's job with ninject?

落爺英雄遲暮 提交于 2019-11-27 21:38:18
I use ninject and quartz.net in my application and I want to inject job with ninject,But I do not know how to ,because all I know is that jobdetail is created by class of Jobimpl instead of an instance,such as: JobBuilder.Create<SomeJob>() Does anyone know how? You'll have to implement an Quartz.Spi.IJobFactory - which uses an IResolutionRoot to create the job (see below for implementation). Then configure the scheduler to use it: Quartz.IScheduler.JobFactory = kernel.Get<NinjectJobFactory>(); (or, alternatively: Quartz.IScheduler.JobFactory = new NinjectJobFactory(kernel); ) public class

Dependency Injection with Custom Membership Provider

≯℡__Kan透↙ 提交于 2019-11-27 21:31:20
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 NHibernate session be passed to its constructor), which then means that the provider cannot access its data

How to use Ninject in a Windows Forms application?

怎甘沉沦 提交于 2019-11-27 21:19:08
I have an WinForms application with this Main Form : ICountRepository countRepository; public MainForm(ICountRepository countRepository) { this.countRepository = countRepository; } public void IncrementCount() { countRepository.IncrementCount(); } but i am struggling to inject ICountRepository into the mainform. How do I do that ? Well the first steps are to switch from: var form = new MainForm(); Application.Run(form); to: var kernel = new StandardKernel( new ModuleRegisteringICountRepository()); var form = kernel.Get<MainForm>(); Application.Run(form); Perhaps a clarifying edit or two about

How to use Ninject with ASP.NET Web API?

半城伤御伤魂 提交于 2019-11-27 21:16:13
In MVC I simply make the class NinjectControllerFactory that implements DefaultControllerFactory interface then do some bindings in it. at last in Global I run it: ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory()); But what about using Ninject in ASP.NET Web API? there are some information on the web but are out dated and for pre-released versions. Is there a straightforward way for this problem? The reason a lot of the articles are old is because the approach hasn't changed since June 2012 (RC released May 31st). You need to add the Ninject MVC3 Nuget package,

Ninject doesn't call Dispose on objects when out of scope

断了今生、忘了曾经 提交于 2019-11-27 20:05:45
I was surprised to find that at least one of my objects created by Ninject is not disposed of at the end of the request, when it has been defined to be InRequestScope Here's the object I'm trying to dispose: Interface: public interface IDataContext : IDisposable { MessengerEntities context { get; set; } } MessengerEntities is Entity Framework's implementation of ObjectContext -- my context object. Then I create a concrete class like so: public class DataContext : IDataContext { private MessengerEntities _context = new MessengerEntities(); public MessengerEntities context { get { return

Custom Authorization MVC 3 and Ninject IoC

*爱你&永不变心* 提交于 2019-11-27 19:54:26
I have a custom authorization class that inherits from FilterAttribute and implements IAuthorizationFilter. I am using the latest version of Ninject w/ asp.net MVC 3 support. The problem I have is I am using constructor injection to inject a repository. But by the the time OnAuthorization is called, the repository is null. Here is the code... public class MyAuthorizeAttribute : FilterAttribute, IAuthorizationFilter { private readonly IMyRepo _MyRepo; public MyAuthorizeAttribute() { } public MyAuthorizeAttribute(IMyRepo myRepo) { _MyRepo= myRepo; //this gets initialized } public void