Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This may be classed as a slightly subjective question but there is very little information on this at the moment, so I just thought I would ask here incase anyone has any experience with this.

I am working on a simple(ish) game for XNA at the moment, but there are quite a few situations where I am wishing I had dependency injection available. Take an example of having a map object which relies upon a tile collection to draw things to the screen, this could be a list of tiles or a spatially partitioned object which would optimise the drawing and update routines. There are lots of other parts where I would rather move the responsibility of binding my application together to a higher level, hence a DI configuration step.

So I know you can use Ninject on XNA with Windows/Xbox/Win7Phone, however I was just wondering if you have any noticeable impact (that is the subjective part). As Ninject must store in memory all its possible bindings ready to dish them out whenever required, although most of the instantiation would be done within IFactory based implementations for relevant entities etc, but I am just worried that Ninject may impose a small performance impact upon loading and storing the bindings in memory.

I am assuming the notice is barely worthwhile noting providing you are just binding your topmost elements and your factory implementations and not making it create EVERYTHING for you, but just wanted to know if anyone had used it before on a major project and any pros/cons they found doing things this way rather than just hard-coding your application composition in your game (or other class).

(I wanted to add the Ninject keyword but dont have enough rep to do so on here)

share|improve this question
add comment

1 Answer 1

If you only need a very limited set of an IoC's functionality you could simply create your own -- especially if you are concerned about the impact. Then you could design it to exactly meet your needs. It could for instance be solved very easily using a static class (God forbid! ;-) that keeps the references you need.

share|improve this answer
    
Along these lines you could register services (under the interface) and request the service in your class that depends on it. See Game.Services. –  George Duckett Mar 15 '12 at 11:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.