开发者

implementing request-reply pattern in .net

开发者 https://www.devze.com 2023-04-03 23:10 出处:网络
Just wanted to know if i am going in the right direction or not. I am implementing Request-Reply (Request-Response) pattern in which every operation sends a request object and gets response object ba

Just wanted to know if i am going in the right direction or not.

I am implementing Request-Reply (Request-Response) pattern in which every operation sends a request object and gets response object back.

For Example:

Public FetchCustomerResponse Fetch(FetchCustomerRequest searchObject)

I am kind of in a confusion about implementing my Repository. I have a generic repositiry interface like this:

public interface IRepositoryReadOnly<TGetRequest, TGetResponse> : IDisposable
{开发者_如何转开发
    TGetResponse FetchAll();
    TGetResponse Fetch(TGetRequest reqObject);
}

public interface IRepositoryReadWrite<TGetRequest, TGetResponse, TPutRequest, TPutResponse> : IRepositoryReadOnly<TGetRequest, TGetResponse>
{
    TPutResponse Insert(TPutRequest dto);
    TPutResponse Update(TPutRequest dto);
    void Delete(long id);
}

The Problem i am having is in void Delete(long id);.

I want my delete method to accept an object which contains other fields like UserName, TimeStamp etc.

Should i create a DeleteRequestObject with the properties and add it to the IRepositoryReadWrite?

This is how it will look if i do that.

public interface IRepositoryReadWrite<TGetRequest, TGetResponse, TPutRequest, TPutResponse, TDeleteRequest, TDeleteResponse> : IRepositoryReadOnly<TGetRequest, TGetResponse>
{
    TPutResponse Insert(TPutRequest dto);
    TPutResponse Update(TPutRequest dto);
    TDeleteResponse Delete(long TDeleteRequest);
}

Since the DeleteRequest and DeleteReponse objects will be same for all the operations (i think so), will this be a good implementation or am i completely off track here and doing all wrong?


I would say that you may go this way, extra Request-Response objects will definitely not harm you.

If at some stage you, for example, find out that you are constantly deleting some entries by id, and to do that you regularly have to create a full request object with one property filled, you can always create an extension method - or even native class method, if you'd like to - that will accept long id and construct the request object for you.

If you leave it with just ids, then on some stage you'll possibly need the request object, but modification will be a whole lot more difficult.

0

精彩评论

暂无评论...
验证码 换一张
取 消