Code is not ready for public consumption just yet, but I'll clean it up and publish as soon as I can.
Anyway, it's called Radiality and it has all the features you would expect from an IoC container, life cycle management, singletons, prototypes, auto-wiring, late injection, look up by interface or name and a few more thing I forgot about.
Here is what it looks like in action.
- container = new RadialityContainer();
- container.Bind<GameConsole>("Console").To(delegate(RadialityContainer r) {
- Game1 game1 = r.Get<Game1>();
- GameConsole console = new GameConsole(game1);
- game1.Components.Add(console);
- return console;
- });
- r.Bind<SpriteFont>("ConsoleFont").To(delegate {
- Game1 game1 = r.Get<Game1>();
- return game1.Content.Load<SpriteFont>("Fonts/LiberationMono12");
- }).InjectNow();
- r.Bind<Texture2D>("ConsoleBackgroundTexture").To(delegate {
- Game1 game1 = r.Get<Game1>();
- return game1.Content.Load<Texture2D>("Textures/ConsoleBackground");
- }).InjectNow();
- container.Bind<Gameplay>().To(delegate(RadialityContainer r) {
- Game1 game1 = r.Get<Game1>();
- Gameplay gameplay = new Gameplay(game1, null, r);
- return gameplay;
- });
1 comment:
There is also Ninject, a quite well-written IoC container that supports the .NET Compact Framework and thus can be easily configured to build for XNA 3.x on the XBox 360 (using Reflection.Emit on the PC and plain invoke via Reflection on the XBox 360).
I have a small example project that demonstrates running Ninject on the 360 here: Using Dependency Injection in XNA
Thanks for the Radiality container. More choice is always a good thing! :)
Post a Comment