ninject

NHibernate, and odd "Session is Closed!" errors

Note: Now that I've typed this out, I have to apologize for the super long question, however, I think all the code and information presented here is in some way relevant. Okay, I'm getting odd "Session Is Closed" errors, at random points in my ASP.NET webforms application. Today, however, it's finally happening in the same place over ...

Ninject giving NullReferenceException

I'm using asp.net MVC 2 and Ninject 2. The setup is very simple. Controller calls service that calls repository. In my controller I use inject to instantiate the service classes with no problem. But the service classes don't instantiate the repositories, giving me NullReferenceException. public class BaseController : Controller { ...

Ninject: Singleton binding syntax?

I'm using Ninject 2.0 for the .Net 3.5 framework. I'm having difficulty with singleton binding. I have a class UserInputReader which implements IInputReader. I only want one instance of this class to ever be created. public class MasterEngineModule : NinjectModule { public override void Load() { // usin...

XNA and Ninject: Syntax for dependency arguments?

I have a class with a public constructor: public MasterEngine(IInputReader inputReader) { this.inputReader = inputReader; graphicsDeviceManager = new GraphicsDeviceManager(this); Components.Add(new GamerServicesComponent(this)); } How can I inject dependencies like graphicsDeviceManager and new Gam...

How to use Ninject with XNA?

I'm having difficulty integrating Ninject with XNA. static class Program { /** * The main entry point for the application. */ static void Main(string[] args) { IKernel kernel = new StandardKernel(NinjectModuleManager.GetModules()); CachedContentLoader content = kernel.Get<CachedContentLoader>(); //...

How do I manage object disposal when I use IoC?

My case it is Ninject 2. // normal explicit dispose using (var dc = new EFContext) { } But sometimes I need to keep the context longer or between function calls. So I want to control this behavior through IoC scope. // if i use this way. how do i make sure object is disposed. var dc = ninject.Get<IContext>() // i cannot use this ...

Ninject 2 + ASP.NET MVC 2 Binding Types from External Assemblies

Hi, I'M just trying to get started with Ninject 2 and ASP.NET MVC 2. I have followed this tutorial http://www.craftyfella.com/2010/02/creating-aspnet-mvc-2-controller.html to create a Controller Factory with Ninject and to bind a first abstract to a concrete implementation. Now I want to load a repository type from another assembly (wher...

Does NInject work in medium trust hosting?

I'm doing shared hosting with GoDaddy and I developed a sample ASP.NET MVC app using Castle Windsor and unfortunately, it didn't work in a medium trust setting. Specifically, I got this error: "[SecurityException: That assembly does not allow partially trusted callers"... etc. GoDaddy is sadly not flexible in their trust policy. I'm not...

Specifying type when resolving objects through Ninject

Given the class Ninja, with a specified binding in the Ninject kernel I can resolve an object doing this: var ninja = ninject.Get<Ninja>(); But why can't I do this: Type ninjaType = typeof(Ninja); var ninja = ninject.Get<ninjaType>(); What's the correct way of specifying the type outside the call to Get? ...

Using Prism with Ninject

Is anyone out there using the Prism framework with Ninject instead of Unity? I need some functionality Unity isn't supporting yet, and I've decided to switch the IoC container to Ninject. I'm struggling a bit with the replace though.. What I need to use from Prism is the EventAggregator and the RegionManager. I have seen this sample th...

How do I set up Ninject with ASP.NET 3.5?

I want to use Ninject to use in a non MVC ASP.NET 3.5 web application. Can someone write please what do I need to download from ninject home site and what steps I need to take (what ddls I need to reference etc.)? I also want to use Moq objects. ...

Can I use Ninject ConstructorArguments with strong naming?

Well, I don't know if "strong naming" is the right term, but what I want to do is as follows. Currently I use ConstructorArgument like e.g. this: public class Ninja { private readonly IWeapon _weapon; private readonly string _name; public Ninja(string name, IWeapon weapon) { _weapon = weapon; _name = ...

Can Ninject be instructed to apply context-based logic to all bindings?

We've begun using Dependency Injection recently, and we've chosen Ninject 2 (for now) as our IoC Container. As I refactor our solution to incorporate DI principles, I've run into something that bugs me a little, and I'm wondering if there's an easy way to get around it. For our data layer, we have a whole bunch of data-access classes t...

Why can't I inject value null with Ninjects ConstructorArgument?

When using Ninjects ConstructorArgument you can specify the exact value to inject to specific parameters. Why can't this value be null, or how can I make it work? Maybe it's not something you'd like to do, but I want to use it in my unit tests.. Example: public class Ninja { private readonly IWeapon _weapon; public Ninja(IWeapo...

NInject2 Interceptor usage with NHibernate transactions

Hello, In my previous project we used NHibernate and Spring.NET. Transactions were handled by adding [Transaction] attribute to service methods. In my current project I'm using NHibernate and NInject 2 and I was wondering if it's possible to solve transaction handling using "Ninject.Extensions.Interception" and similar [Transaction] ...

How to inject dependencies in Collection form ??

How do I wire up dependencies where the dependency is in the form of a collection ?? For Example: public class Ninja { public List<IShuriken> Shurikens {get;set;} public IKatana Katana {get;set;} public void Attack() { // some code goes here to use weapons and kill people } } How do i use a container like Ninject in a case like t...

Ninject: Controller Constructor with int argument

How can you instantiate a Controller that has an int argument? Using Ninject.. My HomeController has a constructor like this: private int _masterId; Public HomeController(int masterId){ _masterId = masterId; } I created a controller factory like this: public class NinjectControllerFactory : DefaultControllerFactory ...

how do use Ninject with class libraries I am developing?

If I am working on a class library how do I make use of Ninject here? i.e., from the internal class library point of view and also from the client code? For example: should the class library have its own IOC set up, or should it always assume the client code will supply? if no (ie it's up to the client to have the IOC in place) then w...

How do I handle classes with static methods with Ninject?

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

Ninject - Asp.net Mvc: Multiple projects in solution

Hello, I was trying Ninject in a Asp.net Mvc application and I was wondering what the best practice is for using Ninject if you have more than 1 project in your solution. I guess all projects need some kind of Loader which you initialize in the global.asax? Kind regards, Pickels ...