xamarin / urho

Code to integrate with the Urho3D engine
Other
464 stars 122 forks source link

Dependency injection for Application #401

Open Haukinger opened 4 years ago

Haukinger commented 4 years ago

The Urho.Extensions.WinForms.UrhoSurface uses Activator.CreateInstance to produce the application instance in Show. This means that one cannot inject any dependencies and has to resort to some static service locator.

It would be cool if there was a Show overload that took a Func<ApplicationOptions, Application> to produce the application instance which could be made to redirect to the dependency injection container in use.

hwd71 commented 4 years ago
Can you pass in a subclass of ApplicationOptions to the ctor?(that’s what I do, but not sure for winforms..)   Sent from Mail for Windows 10 From: HaukingerSent: 14 June 2020 16:23To: xamarin/urhoCc: SubscribedSubject: [xamarin/urho] Dependency injection for Application (#401) The Urho.Extensions.WinForms.UrhoSurface uses Activator.CreateInstance to produce the application instance in Show. This means that one cannot inject any dependencies and has to resort to some static service locator.It would be cool if there was a Show overload that took a Func to produce the application instance which could be made to redirect to the dependency injection container in use.—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or unsubscribe.  4 The Quadrangle, Grove Business Park Downsview Road, Wantage, Oxfordshire, United Kingdom, OX12 9FA+44 (0)1235 227 360www.airboxsystems.cominfo.airboxsystems.comTHIS E-MAIL IS DESIGNATED AS PROTECTED AND IS FOR YOUR EYES ONLY.
Haukinger commented 4 years ago

Can you pass in a subclass of ApplicationOptions to the ctor?

This works, actually, but the code looks rather ugly.

I've made the derived options type that gets all the dependencies a nested class in my urho application, and the attached property that calls UrhoSurface.Show uses the common service locator to create the options instance.