Create registration pattern with C# UI repository

Asked

Viewed 388 times

0

I created in my system a repository with EF6, each registration I do access the methods of my repository to commit the actions I need (Insert, Delete etc...). The problem is that my system is very large and I need to gain agility when creating registrations, I then thought about creating a control with the screen pattern that I need and the buttons that will call my repository to perform the actions I think about creating properties informed which is the table of my Model. Someone has some north for me to create something like?

  • use DI so you pass the interface

  • Do you have any example?

1 answer

1

I would do something using Generics:

public interface IComum<T>
    where T: class, IModeloDeDados
{
    IEnumerable<T> Selecionar();
    IEnumerable<T> Selecionar(IEnumerable<Operador> parametros, IEnumerable<string> campos = null);
    void Incluir(T objeto);
    void Atualizar(T objeto);
}

I’ve sharpened the question in this answer.

Just clarifying, in this my example a Operador is a special class that is transformed into an SQL sentence because the project does not use Entity Framework, but there are other answers here with the implementation supporting lambda expressions.

Get your repository classes to implement this interface, passing as type in T the desired data object:

public class Pessoas : Comum<Pessoa> { } 

Pessoa, in this case, you need to implement an interface IModeloDeDados, so that the repository does not accept any object.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.