In this chapter, we can briefly discuss about dependency injection. we have already included information binding decouples views and ViewModels from each different that allows them to speak without knowing explicitly what goes on at the other end of the communique.
Now we want something similar to decouple our ViewModel from the client services.
In early days of object-orientated programming, builders have confronted the problem of making and retrieving times of classes in programs. various solutions had been proposed for this problem.
For the past few years, dependency injection and inversion of control (IoC) have gained recognition among developers and feature taken precedence over some older solutions including the Singleton pattern.
IoC and dependency injection are two layout patterns which can be closely associated and the container is basically a chunk of infrastructure code that does each of those styles for you.
Let’s have a look at how we will use dependency injection to break decoupling among ViewModels and the client services. we will wire up the save handling AddEditCustomerViewModel shape through using dependency injection related to that.
First we want to create a new interface in our task in services folder. if you don’t have a services folder on your project then create it first and upload the following interface in the services folder.
Following is the implementation of ICustomersRepository.
The simple way to do keep handling is to add a new example of ICustomersRepository in AddEditCustomerViewModel and overload the AddEditCustomerViewModel and CustomerListViewModel constructor.
Update the OnSave method as shown in the following code.
Following is the complete AddEditCustomerViewModel.
When the above code is compiled and done, you may see the same output but now ViewModels are more loosely decoupled.
When you press the upload customer button, you may see the following view. when the user leaves any subject empty, then it becomes highlighted and the save button becomes disabled.
MVVM Related Interview Questions
|C#. NET Interview Questions||. NET Interview Questions|
|Adv Java Interview Questions||Android Interview Questions|
|Graphic Design Interview Questions||LINQ Interview Questions|
|Web Developer Guide Interview Questions||Apache Cassandra Interview Questions|
|Windows Presentation Foundation(WPF) Interview Questions||Advanced C# Interview Questions|
|XAML Interview Questions||Blue Prism Interview Questions|
|Windows Forms Interview Questions|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.