urho
urho copied to clipboard
Dependency injection for Application
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.
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 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.
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.