winforms - Using Ninject to inject dependencies into externally constructed objects (user control) -


I would like to use Ninject in my WinForms application. I can not understand how I can use it for my user controls Sometimes they rely on the services I want to configure through the DI Framework. These controls should be arranged through the designer (thus requiring a default constructor).

So is there a way to inject dependency in the properties of this user control? Since the designer should be able to make it, because kernel.Get & lt; TestClass & gt; Will not work here Is there any way or some code that will "fill" the dependency in the Form_OnLoad () method?

I can also think of other examples where I would like to inject the properties of already present objects, but th WinForms user control is easy to understand.

I think that you should invert your thinking, there is only one responsibility in the scene: To display data

How does this data get, the controller has the responsibility, and how it is shown in the model memory is determined by the model.

However, there is no specific MVC framework for Windows Forms, it is possible to manually create raw ones, or you can see it (now retired) how it can be done (though CAB Probably too complex for most people's tastes) Today there are more elegant alternatives available, but they include WPF.

In any case, to give your dependency injections in your scenes, rather than controlling them in the controllers, see the controller instant and properly visual (your control).

In this way, you can keep your controls free from fear of free, as they should be.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -