Answer the question
In order to leave comments, you need to log in
What does it mean to inject and also create one class from another (MVP pattern) in C#?
Hello!
There is a scheme for the interaction of classes with each other according to the MVP (Model-View-Presenter) principle. (1) One interaction is described as follows: The Presenter injects (Databases added in brackets) Services. (2) Or another interaction: Presenter creates (in brackets CurrentRecord) Model.
I know that (1) implies Dependency Injection, but I don't understand how it should work here, because. I haven't had to deal with DI yet.
And according to (2), the question is also: does this mean that it is necessary to create objects of the View type in the Presenter class?
Thanks for any insights.
Answer the question
In order to leave comments, you need to log in
1. Injects, which means it does not create an instance within itself (i.e. does not make new Service()), but takes Service as a parameter, most often as a constructor parameter
var service = new Service();
var presenter = new Presenter(service);
eRK Thank you. (2) Yes, I'm sorry, I meant Model, not View, a typo. And what can mean CurrentRecord in brackets? This is some kind of current model. How would this look like in code?
Here, for example, it stands: from View (this is no longer a typo :)) a single instance is created through the DI Container. What is a DI Container ?, is it when "something" is passed through a parameter?
(1) And here, probably in brackets, we mean the Service for communicating with the Database. Those. The Presenter takes the Service as a constructor parameter, thereby dynamically communicating with it, and through the Service there is a dialogue with the database, perhaps so?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question