ninject

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

99封情书 提交于 2019-12-01 07:32:15
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? You cannot have ninject instantiate stuff in case you don't ask it to instantiate something yourself. The simple way is to ask ninject to instantiate things at composition root: var kernel

How to inject dependencies using Ninject In ASP.NET WebForm?

痞子三分冷 提交于 2019-12-01 07:13:56
问题 I have a fair idea of using the Repository Pattern and have been attempting to "upgrade" our current way of creating ASP .Net websites. So i do the following Create a solution with a class project called DataAccessLayer and another class project called BusinessLogicLayer . Finally a 3rd project which is my ASP .Net website (a normal site). I add a dbml file to the DAL and drag a table, then in my BLL i add an interface and a class which implements this interface: My interface namespace BLL

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

Bind a Global Action Filter to all Controllers in an Area using MVC 3 Dependency Injection with Ninject 2.2

烂漫一生 提交于 2019-12-01 06:36:53
I was able to to use ASP.NET MVC 3 and Ninject 2.2 to inject a logger object into a custom ActionFilterAttribute thanks to the help I received in this post . Now I would like to bind my custom ActionFilterAttribute only to all controllers that are in a specific area. I was able to get started with the following binding but it only handles one controller in a certain area. I would like my code to bind to all controllers in a specific area. Any ideas? /// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static

MVC3 EF Unit of Work + Generic Repository + Ninject

陌路散爱 提交于 2019-12-01 06:12:32
I'm new to MVC3 and have been following the awesome tutorials on the asp.net website. However, I can't quite wrap my head around how to use Unit of Work and Generic Repository patterns with Ninject. I used this tutorial as a starting point: http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application Without using interfaces, I know I can implement it like so: Generic Repository: public class GenericRepository<TEntity> : IGenericRepository<TEntity> where TEntity : class { internal MyContext context;

Does Ninject automatically inject non-bound classes?

走远了吗. 提交于 2019-12-01 06:10:46
public class MyController : Controller { private MyClass _class; public MyController(MyClass class) { this._class = class; } } public class MyClass { // stuff } My Ninject is hooked up to inject classes that implement IController ( Controller class does so). But, I did not bind MyClass to anything, yet Ninject is still injecting MyClass into MyController . I guess my question is, why does it inject something that I didn't bind to anything? Does Ninject run off an find the class with the signature MyClass ? I assume this behavior would be different if my constructor required a MyBaseClass and I

Ninject Dependency Injection for SignalR

百般思念 提交于 2019-12-01 06:07:04
In my NinjectWebCommon.cs file, under CreateKernel method I am applying the injection like this private static IKernel CreateKernel() { var kernel = new StandardKernel(); kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel); kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>(); RegisterServices(kernel); // Web API Injection GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel); // SignalR Injection GlobalHost.DependencyResolver = new SignalR.Ninject.NinjectDependencyResolver(kernel); return kernel; } I was

How do you resolve a Ninject dependency in the global file in ASP.NET?

余生颓废 提交于 2019-12-01 05:47:28
问题 I am using the Ninject and Ninject.Web assemblies with a web forms application. In the global.asax file I specify the bindings like so: public class Global : NinjectHttpApplication { protected override IKernel CreateKernel() { IKernel kernel = new StandardKernel(); // Vendor Briefs. kernel.Bind<IVendorBriefRepository>().To<VendorBriefRepository>().InRequestScope(); kernel.Bind<IVendorBriefController>().To<VendorBriefController>().InRequestScope(); // Search Services. kernel.Bind

Ninject and XML configuration Binding

心不动则不痛 提交于 2019-12-01 05:33:26
i have been searching the internet for any sample or getting start article on how to do binding with Ninject using XML extension but i couldnt find any help ! , can any body provide me with a very small sample on how can i do that ? thanks in advance cbp I can't find any examples either, but honestly the source code is very small - I would just download ( here ) and read through the test cases. The unit test project has some examples, like this: <module name="basicTest"> <bind name="melee" service="Ninject.Extensions.Xml.Fakes.IWeapon, Ninject.Extensions.Xml.Test" to="Ninject.Extensions.Xml

MVC3 EF Unit of Work + Generic Repository + Ninject

女生的网名这么多〃 提交于 2019-12-01 05:30:51
问题 I'm new to MVC3 and have been following the awesome tutorials on the asp.net website. However, I can't quite wrap my head around how to use Unit of Work and Generic Repository patterns with Ninject. I used this tutorial as a starting point: http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application Without using interfaces, I know I can implement it like so: Generic Repository: public class