ninject

How to use non-default contructors with Ninject?

How to use Ninject with a sample code for interface and its implementation like this: public interface IRepository { // common methods for all content types void Insert(BaseContentObject o); void Update(BaseContentObject o); void Delete(string slug); void Delete(ContentType contentType, string slug); IEnumerable<...

Return same instance for multiple interfaces

I'm registering components with the following code: StandardKernel kernel = new StandardKernel(); string currentDirectory = Path.GetDirectoryName(GetType().Assembly.Location) foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { if (!Path.GetDirectoryName(assembly.Location).Equals(currentDirectory)) continue;...

Ninject: Method not getting intercepted in Silverlight

Hi All I use Ninject for DI in Silverlight app. Now I am trying to implement interception and having issue. My methhod is not getting intercepted. Below is sample implementation public class InfrastructureModule : NinjectModule { public override void Load() { Bind<IGlobalEventManager>().To<GlobalEventManager>().InSingle...

Ninject how to access kernel to create instances?

I am new to ninject using ninject 2.0. My application is hosted in asp.net mvc. Now i don't know how to access kernel created in my class library. I think i should create kernel in global.aspx and load all modules in it. But how can i make it available throughout application? protected void Application_Start() { Regist...

Ninject 2.0: Property Injection without attribute

Is there a way to use Property Injection in Ninject 2 without using the [Inject] attribute? This creates a dependency to Ninject in the class that will be wired using it and I prefer to avoid having unneeded dependencies to my IoC container, that's why I end up using Constructor Injection more often. I guess the same applies to Method I...

scoping NHibernate ISession in a spawned Thread with NInject

Ok, here's the scenario. I have an ASP.NET site that periodically spawns a background thread to do some jobs. the thread's execution consists of a JobRunner that iterates through a list of IJobs and calls Execute() on each one. JobRunner and each IJob is created by NInject. A couple of the IJobs have a dependency to IRepository<Model...

Unit Testing with Nunit, Ninject, MVC2 and the ADO.Net Entity Data Model

I'm trying to get my head around using Nunit, Ninject, MVC2 and the ADO.Net Entity Data Model. Let's say I have have a ProductsController instantiating a SqlProductsRepository class. public class ProductsRepository : IProductsRepository { public MyDbEntities _context; public ProductsRepository() { _context = new My...

using Ninject with ASP.NET MVC and services layer

I have an ASP.NET MVC project which uses a services project to go through a set of interfaces (project) to a repository project. I am slightly confused where to use Ninject. It seems logical to me that i include my Ninject in the services layer as this is where i interact with the interfaces. My question is how would this be implemen...

Ninject 2 missing RegisterAllControllersln?

I'm totally a newbie with Ninject and I tried to follow the tutorial by Shiju Varghese at his blog post about DI. I did add reference of ninject.dll and Ninject.Web.Mvc.dll However, I got stuck as Visual Studio cannot resolve the function RegisterAllControllersIn.... protected override void OnApplicationStarted() { Are...

How to configure Ninject for ASP.NET MVC using LinqToSQL and Repository Pattern

I have done some searching around but have not been able to figure out how to bind LinqToSql data context's with specified connection strings into different repositories. This binding is performed in global.ajax when routes are registered. I'm using a fairly standard repository pattern to decouple the LinqToSql infrastructure from my ap...

IoC Container Hurdle for ASP.Net MVC Newb

Hi, I must admit that I'm new to ASP.Net MVC and I'm currently researching all the best practices on how to start my new project. So far I have understood the concepts of the Repository Pattern and Unit of Work and I have gone onto Dependency Injection and Inversion of Control (IoC). I have been looking into this for the last 2 days an...

Ninject dependency injection into ASP.NET MVC controller where repository type is known only at runtime

I've set up DI with Ninject in my ASP.NET MVC application like this Bind<IRepository>().To<XmlDefaultRepository>().WhenInjectedInto(typeof(PageController)).WithConstructorArgument("contentType", ContentType.Page); Bind<IRepository>().To<XmlDefaultRepository>().WhenInjectedInto(typeof(WidgetController)).WithConstr...

Ninject to bind on different controllers

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 the...

Resolving automatic and manual dependencies

Hi! I´m having a little bit of trouble sorting a way to manage automatic resolved and manual dependencies in my classes. Let´s say I have two classes to calculate prices: one calculates how much I will charge for shipping and the other how much I will charge for the entire order. The second uses the first in order to sum the shipping p...

When to use Singleton vs Transient vs Request using Ninject and MongoDB

I'm not quite sure when I should use SingletonScope() vs TransientScope() vs RequestScope() when I do my binding in my global.cs file. I have for example my call to MongoSession (using NoRM and the mvcStarter project http://mvcstarter.codeplex.com/) which is set to SingletonScope but I created a repository that use this MongoSession obj...

Looking for Dependency Injection examples and clear tutorials with Ninject 2.0 for C# ASP.NET (NOT MVC)

I have been searching for a while. I'm not new to dependency injection and have used StructureMap with several projects MVC and the like, but I felt like giving Ninject a go, so as not to miss out on the fun. I am trying to use Ninject with an existing web app which I am bringing up-to-date. I couldn't find on the blogs and wiki provi...

How do you make a Generic Generic Factory?

I am working on a client (Silverlight) interface to a collection of webmethod. And I am trying to avoid writing any custom code for every webmethod. So I have created a ServiceCall<TResult> to handle each call, TResult specifies the return type of the service (I use XmlSerializer to create the returned instance). The client class exposes...

ASP.NET MVC 3 Preview configure for ninject

I'm giving ASP.NET MVC 3 Preview 1 a spin and want to configure ninject with it. Is the best way still to use ninject.web.mvc extension? The sample Scott Gu posts doesn't run. It throws an "Error activating IControllerFactory" exception. ...

How to configure Automapper to be injected with Ninject 2.0?

There are configuration examples for Structure Map and Windsor: http://www.cprieto.com/index.php/2009/08/20/using-automapper-with-castle-windsor/ But I haven't found anything for Ninject. Do you know how to translate those mappings to Ninject? ...

Where to store Ninject IKernel in a web application?

I am new to IOC in general and I'm struggling a little to understand whether what I am trying to do makes any sense. I have a web forms application in which I want to create one module to define some bindings for me. The bindings will be used to inject repositories into my business manager classes, allowing me to unit test the business...