-1
I’m creating a web service WCF
which will expose methods to do CRUD operations in a database. And I’m having doubts on how to create the contract interface.
The Service will enable CRUD in multiple tables and will involve many complex types such as Client
, Address
, Dependent
, Functionary
, etc.
I created the contract interface called IDataPersistance
and so far:
[ServiceContract]
public interface IDataPersistance
{
[OperationContract]
bool Insert ( object value );
[OperationContract]
bool Change ( object value );
[OperationContract]
bool Delete ( object value );
// TODO: Adicione suas operações de serviço aqui
}
The problem is that to insert a Client the method Insert
must receive an object Client
, to insert a Address the method Insert
must receive an object Address
, so on.
The same also happens as a method Delete
. In some cases (such as to delete a Address) he gets a string
as a parameter and in other cases a int
.
I am weighing on how I could create an interface (generic ?) that serves as a contract for CRUD operations involving any type.
Or in this case I have no way to escape and will have to create a CRUD interface for each object that will be persisted in the bank? That is, an interface for CRUD Customers, another for CRUD of Dependent, etc.. ?
Great! Also, I found that you can restrict where the generic type can be used, whether only in the return or only in the parameters link.
– Matheus Saraiva