A quick demonstration for using Dependency Injection in .NET Framework 4.7 WinForms Application with MVP Pattern.
Package Name | Version |
---|---|
Microsoft.Extensions.DependencyInjection | 5.0.1 |
You should register your services in ConfigureServices() method. The Service Provider property should be in Program.cs too. Method named GetService is just added for handling your service object easier.
As I mentioned before, we are going to use GetService method from Program.cs to call our service objects here.
Now we are calling method from presenter like we do.
In this sample, executing UI method from UserView which calls from UserPresenter that references IUserService which is the origin reference of method implemented in UserService.