简体   繁体   English

在.net中实现请求-答复模式

[英]implementing request-reply pattern in .net

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); 我遇到的问题是void Delete(long id); .

I want my delete method to accept an object which contains other fields like UserName, TimeStamp etc. 我希望我的delete方法接受一个包含其他字段的对象,例如UserName, TimeStamp等。

Should i create a DeleteRequestObject with the properties and add it to the IRepositoryReadWrite ? 我应该使用属性创建DeleteRequestObject并将其添加到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? 由于DeleteRequest和DeleteReponse对象对于所有操作都是相同的(我认为是),因此这将是一个很好的实现,还是我完全偏离了正常进行所有错误?

I would say that you may go this way, extra Request-Response objects will definitely not harm you. 我要说的是,您可以这样走,多余的Request-Response对象绝对不会伤害您。

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. 例如,如果您在某个阶段发现自己不断通过ID删除某些条目,并且要定期创建一个填充了一个属性的完整请求对象,则可以始终创建扩展方法-甚至是本机方法类方法,如果您愿意-将接受long id并为您构造请求对象。

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. 如果仅用id保留它,那么在某个阶段您可能会需要request对象,但是修改会困难得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM