Problems using a builder


I am working on a windows forms application, in which I use ninject, the problem is that in the constructor of my userControl I implement to use my CRUD operations.

public partial class ucProveedor : UserControl, ICommandAction
    private ISaProveedor _repositoryProveedor; 
    public ucProveedor(ISaProveedor repositoryProveedor)
        _repositoryProveedor = repositoryProveedor;

Then when I call the userControl he asks me for a parameter.

private void btnMenuProveedor_Click(object sender, EventArgs e)
    ucProveedor _proveedor = new ucProveedor();

What can I do?

asked by Pedro Ávila 12.04.2016 в 00:21

1 answer


If you use Ninject you can not do a new of the instance of ucProveedor, you must solve it using the method Get<>() of IoC container (or ninject) since this is the one who knows how to inject the instance of the constructor.

Dependency Injection in WinForms using Ninject and Entity Framework

You could help with the library


The idea is that you can define the


Then you can use

ucProveedor _proveedor = kernel.Get<ucProveedor>();

as you get the instance using factory niject, this will assign the instance you need in the constructor

Note: I'm not sure if ninject allows you to map a specific class with your same class, but it's just a matter of trying it.

answered by 12.04.2016 / 01:47