Linked Questions
19 questions linked to/from How to handle dependency injection in a WPF/MVVM application
122
votes
3
answers
55k
views
What is a ViewModelLocator and what are its pros/cons compared to DataTemplates?
Can someone give me a quick summary of what a ViewModelLocator is, how it works, and what the pros/cons are for using it compared to DataTemplates?
I have tried finding info on Google but there seems ...
21
votes
6
answers
24k
views
Dependency Injection in .NET Core 3.0 for WPF
I’m quite familiar with ASP.NET Core and the support for dependency injection out of the box. Controllers can require dependencies by adding a parameter in their constructor. How can dependencies be ...
5
votes
1
answer
4k
views
Dependency Injection into a UserControl
I'm using C# 6.0, WPF 4.5.2 and the PRISM-architecture 6.2.x (Unity). And I'm using a class derived from Canvas.
So, there is a class MyCanvas, which is used in a UserControl (XAML) in the way of:
&...
1
vote
2
answers
2k
views
WPF - MVVM - Who is responsible for a new DataProvider Connection?
I know this might be a "style of coding" question but at this point I'm really confused. Currently I'm trying to follow the MVVM pattern (ViewModel, Repository, Controller etc.)
But who should ...
7
votes
1
answer
2k
views
Global instance of a class or static class with initialization method
I have a class that handles the Localization of my application. My goal is that the class is usable in the entire application so I made it static. This allows me to call the code below anywhere in my ...
2
votes
1
answer
4k
views
using autofac in MVVM application
My application is going on a break mode after hitting a user button that loads the app setup. I have registered the component in the bootstrapper class.
How can I register the constructor of the ...
4
votes
2
answers
3k
views
How can I initialize a property in a viewmodel when creating a new view?
I have an application that opens a view that allows you to search for data. However, in order to to search, the user has to select what category he wants to search under. Currently, I'm trying to ...
1
vote
1
answer
4k
views
WPF MVVM: Dependency Injection Without Constructor Overloading Many Parameters
I am building a WPF Application, which has a single Window, a tabbed interface with multiple view models (2 view models, the first tab is ViewModel1 and the rest will always be ViewModel2) these are ...
2
votes
1
answer
2k
views
Dependency Injection using ninject not working
My goal is simply this: I want the already existent instance of class "MainWindowVM" (implementing IMainWindowVM) to be injected into class "StaticTestsResultsViewModel". I do not(!) want a new ...
1
vote
1
answer
2k
views
Why my Subscribe method is not called when using Prism EventAggregator?
I am learning Prism. Few hours already I am facing a problem, when subscribing to the event, the subscription method is not called. I am using Prism and Autofac.
In the simplified example below, in ...
1
vote
2
answers
910
views
How to connect View and ViewModel if ViewModel constructor has parameters?
My ViewModel:
public class MainViewModel : INotifyPropertyChanged
{
private User selectedUser;
private IUserRepository _userRepository;
public List<User> Users { get;...
0
votes
1
answer
666
views
Why my Autofac registered Prism EventAggregator is not injected properly into viewmodel? [duplicate]
In my solution I am using Autofac, and Prism as well. Below is a simplified project that explains what happens.
I am registering my views, view models and EventAggregator in Autofac's container class ...
0
votes
1
answer
488
views
Correct way to data-bind collections to ComboBox in WPF using MVVM?
I'm using MVVM pattern, developing my WPF application. I also use Entity Framework as ORM. Here're my models (EF):
public class User : BaseEntity
{
public string Name { get; set; }
public ...
0
votes
1
answer
577
views
Accessing Container instance with LighInject
When using LightInject, how can you use access the Container instance in contexts other than initial registration/bootstrapping? I followed LightInject's getting started guide and google around, but ...
1
vote
1
answer
258
views
How do you inject non-presentation dependencies like a repository in a WPF application without involving the presentation layer (i.e. view model)?
I'm trying to apply DI to my WPF application (with MVVM). I would like to adhere to an onion architecture, and as such, my model has an IRepository interface which is injected via an IoC container ...