Reputation: 21286
I'm looking for a way to inject dependency without calling Ninject's Get
method.
For example in ASP.NET MVC I create a class that inherits from DefaultControllerFactory
MSDN, and add it to the controller builder's factory with ControllerBuilder.Current.SetControllerFactory
MSDN. Once I do that, I never call Get
, and it fills in automatically.
Is there an equivalent for WPF?
I need a general answer that will fit most situations but if I have to give an example, I made a control in WPF, However it has a parameter in the constructor:
public AppVolumeSlider(IVolumeSetter volumeSetter)
Since my controls are in markup, WPF complains, of course: The type "AppVolumeSlider" does not include any accessible constructors.
.
How can I make Ninject/WPF fill it appropriately?
Note 1: If I can't do it in this example (I guess because of the markup) please give me a general answer. For example if I just make a class with a similar constructor and not a control. I still need to know this information.
Note 2: I have a hunch this might be related to the Inject
attribute, but I have no idea.
Thank you.
Upvotes: 2
Views: 494
Reputation: 4157
Some containers, like Unity have a function to provide dependencies to already existing instances. Of course this will not work for construcor injection. But it will work find for propery/method injection.
You can create your WPF Page (or whatever control), it will load markup, and then call Unity.BuildUp(your_object).
Or equivalent function of different container.
Upvotes: 0
Reputation: 32725
Have a look at the various MVVM frameworks like Caliburn Micro: http://caliburnmicro.codeplex.com/ Most of them come with IoC container support.
Upvotes: 1