Hizmet katmanında İstek/Yanıt kalıbı kullanıyorum. Ben örneğin, var şu şekildedir: SonraYanıt/İstek şekli ... DTO'lar nasıl şekillendirilir?
public class FindPostsByTypeHandler : Handler<FindPostsByTypeRequest, FindPostsByTypeResponse> {
private IContext _context;
public FindPostsByTypeHandler(IContext context) {
_context = context;
}
public FindPostsByTypeResponse Handle(FindPostsByTypeRequest request) {
IList<FindPostsByTypeRequest.PostDto> posts = _context.Posts
.Where(x => x.Type == request.Type)
.Select(x => new FindPostsByTypeRequest.PostDto {
Id = x.Id,
Title = x.Title,
Text = x.Text
}).ToList();
return new FindPostsByTypeResponse { Posts = posts };
}
}
Bir hareket memurunu var ve kullanmak:
FindPostsByTypeRequest request = new FindPostsByTypeRequest { Type = type };
FindPostsByTypeResponse response = _dispatcher.Send<FindPostsByTypeResponse>(request);
Sorun
public class FindPostsByTypeRequest : Request {
public PostType Type { get; set; }
}
public class FindPostsByTypeResponse : Response {
public IList<PostDto> Posts { get; set; }
public class PostDto {
public Int32 Id { get; set; }
public String Title { get; set; }
public String Text { get; set; }
}
}
Bir işleyicisi var bu isteği işlemek için:
'u çözmeye çalışıyorum. Ometimes etiketlere ihtiyacım var ... Bazen yapmam. Tabii hep DTOs içine etiketlerini almak ve kullanmak ya da değil ... Ama kaçınılmalıdır gerekmez şey yükleniyor ...
Böylece temelde Türüne göre Mesajını almak gerekir olabilir ve İşleyiciye hangi verileri ihtiyacım olduğunu söylerim.
Benim fikir olacağını bir şey gibi: PostWithTagsModel ihtiyacım olacağını DTO olurdu
_dispatcher.Send<FindPostsByTypeResponse<PostWithTagsModel>>(request);
. Sonra benim İşleyicisi'ndeki ben olurdu: Bu mümkün veya bunu yapmak için bile en iyi yoldur emin değilim
public class FindPostsByTypeHandler : Handler<FindPostsByTypeRequest, FindPostsByTypeResponse> {
private IContext _context;
public FindPostsByTypeHandler(IContext context) {
_context = context;
}
public FindPostsByTypeResponse<PostsByType> Handle(FindPostsByTypeRequest request) {
IList<FindPostsByTypeResponse.PostDto> posts = _context.Posts
.Where(x => x.Type == request.Type)
.Select(x => new FindPostsByTypeResponse.PostDto {
Id = x.Id,
Title = x.Title,
Text = x.Text
}).ToList();
return new FindPostsByTypeResponse { Posts = posts };
}
public FindPostsByTypeResponse<PostsWithoutTagsDto> Handle(FindPostsByTypeRequest request) {
IList<FindPostsByTypeResponse.PostsWithoutTagsDto> posts = _context.Posts
.Where(x => x.Type == request.Type)
.Select(x => new FindPostsByTypeResponse.PostsWithoutTagsDto {
Id = x.Id,
Title = x.Title,
Text = x.Text
}).ToList();
return new FindPostsByTypeResponse { Posts = posts };
}
public FindPostsByTypeResponse<PostsWithTagsDto> Handle(FindPostsByTypeRequest request) {
// Remaining code
}
}
...
Temelde ben işleyicisi "anlatmak" gereken hangi biçimde ben Yanıtta yer alan DTO'lara ihtiyaç duyar.Bunu nasıl yapabilirim veya yapmalıyım?
Pek değil. Daha genel bir şeye ihtiyacım var ve ne tür bir isteğimi istediğime girmem gerekiyor. Örneğindeki dispacther'i nasıl kullanırsın? –
yan not ... Hiç böyle bir çılgın formatlama görmedim – AlexFoxGill
Biçimlendirme, ctrl M-O kullanılarak daraltıldıklarında yöntemlere bakarken kullanışlıdır. Buradaki fikir, bir kerede bir kerede bir yönteme bakmaktır. Temel olarak birinci sekme durağı değiştirici sütundur, ikincisi tip/dönüş tipi sütundur, üçüncüsü özellik/alan/yöntem adıdır ve dördüncü isteğe bağlı alan başlatma veya özelliktir {get; ayarlamak;}. –