urho icon indicating copy to clipboard operation
urho copied to clipboard

Dependency injection for Application

Open Haukinger opened this issue 4 years ago • 2 comments

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.

Haukinger avatar Jun 14 '20 15:06 Haukinger

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.

hwd71 avatar Jun 15 '20 13:06 hwd71

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.

Haukinger avatar Jun 27 '20 11:06 Haukinger