Constructor parameters for Game class in UWP?

Hi all!

So I’m trying to get my game working with UWP and I’m injecting some stuff in the game class constructor for other platforms, mostly platform-specific stuff like file access etc.

However, in UWP I’m not responsible for creating an instance myself:

MonoGame.Framework.XamlGame<MyGameClass>.Create(launchArguments, Window.Current.CoreWindow, swapChainPanel);

Also this seems to call Initialize & LoadContent directly before returning. So there’s no way to kind of push the deps into it with a game.Configure(deps..) or something like that.

So my question basically is “how do I inject platform specific dependencies in UWP”?

Can you describe more about what you are doing with the injection of code? There may be another way of doing it that works better across platforms.

Personally, I would add your own functions to your game class.
Then just after

 Game myGame = new Game();

I would then add


Then when it initialises the XamlGame all you dependencies will be loaded before any LoadContent / Update calls.

That’s what I have. But for UWP that doesn’t quite work.
MonoGame.Framework.XamlGame<MyGameClass>.Create(launchArguments, Window.Current.CoreWindow, swapChainPanel);

This function actually instantiates the Game class and Initialize and LoadContent are called before it returns.
So when I need the deps int LoadContent for example, it’s already too late to manually load them.

I’m seriously considering adding a fire-once event in the update to actually do the loading but that feels sooo dirty.

OK, dug a little deeper and I see what you mean.
Only suggestion then is to have a static dependency manager where you can register the dependencies, and then retrieve / call them from Game.initialise.

That way they will be called before LoadContent and the first Draw loop (I think Update will be called at least once before)

Not perfect and means having a static class that you will have to manage but it should work.

To be fair, in old MVVM projects I did, this was the pattern you needed to manage multiple dependencies.

Hi erik!

Just to inform you, I opened an issue for this with a proposal of Pull Request as it is a problem for me too.

Link to the issue