Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[Question] Do we have a reason to use dynamics type in OrderQueries.cs file #366

Closed
SychevIgor opened this issue Oct 9, 2017 · 2 comments

Comments

@SychevIgor
Copy link
Contributor

I just started working on #305 and got an interesting situation... I can't normally describe the return type for OrderController.GetOrder because type essentially dynamic.
after some research - I didn't find any reason for dynamic type here.
May I fix the type or could you explain the idea?

@CESARDELATORRE

@CESARDELATORRE
Copy link
Collaborator

CESARDELATORRE commented Oct 31, 2017

@SychevIgor
The reason is that being dynamic, you can just change the SQL query (new attributes/columns, etc.) and you'll get that returned. you have like a dynamic ViewModel. No need to have static classes for those ViewModels. So, it is more agile when developing.
So, for a service used only by the same application, it is ok and more agile.

However, for a public API, it would be better to use ViewModels or "contracts".
And even for a long term application, I find that having explicit ViewModel classes is safer and also, as you mentioned, better for Swagger or even other "unknown clients".
So, after testing that PR well, we can merge it. But, can you test it with all the client apps? Including the SPA app and the Xamarin app?

Here's a longer explanation:
https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/microservice-ddd-cqrs-patterns/cqrs-microservice-reads
(Scroll down until you see the "Dynamic and static ViewModels" title).

As I said, that approach was very agile and flexible while developing, but once the app is stable and we think more in the long-term, I find that it might be safer to define explicit ViewModels (like DTOs) exposing explicit contracts.
Thoughts?

@CESARDELATORRE
Copy link
Collaborator

Closing this issue. We decided to accept the PR and use predefined ViewModel DTOs classes as it is better for public APIs but also for long term microservices, even if they are just used by the same application.
Also, as mentioned by SychevIgor, if you want to specify response types for swagger, you need to use explicit DTO classes as the return type. Therefore, predefined DTO classes allows you to offer a richer information from Swagger. That will benefit the API documentation and compatibility when consuming an API.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants