0

I have a question for you.

I have a .NetCore proyect with a hexagonal architecture. In my repository class I fill my domain class that its name is company and has two properties: Id and Logo.

My repository returns de Id and the logo name, but not the all url path, so I want to set the logo property with put my image path url before de name, like this http://example.com/imageName.jpg.

So my question is, in a hexagonal architecture where is the best practise to set this property ?

Now In my Controller I create a DataModel that pass my domain class for the constructor, and inside the model I build the image logo url.

So, do you thing is the best way to do that ?

Thanks!

Mr.Beto
  • 105
  • 4
  • 11
  • In Hexagonal Architecture, the hexagon (i.e. the business logic, the application) is technology agnostic, it shouldn't know about http. You should abstract the logo location, the hexagon doesn't care about where the logo is located/stored. You can locate it at the db with the other company data, or if you want to keep it apart you could get it through a driven port just for the logo – choquero70 May 22 '20 at 06:38

2 Answers2

0

Knowing how to store & retrieve resources such as blobs is certainly the responsibility of the infrastructure layer, but just like for repositories, the interface of such service probably lives within the domain.

If you have a clean application service layer then I'd put the URI resolution (through the domain service) there as part of a DTO response consumed by the controller, but if the controller layer acts as the application service layer then it would go there.

plalx
  • 39,329
  • 5
  • 63
  • 83
  • But If I put this in the controller or domain, I need to do a foreach por set this property. So, maybe is good idea to put this string inside the query I use in the repository layer. Because when I fill my object inside the repository layer, my object will have the url image plus the name of image. What do you think ? – Mr.Beto May 18 '20 at 15:27
  • @Mr.Beto It shouldn't change much in terms of performance. Many operations per loop isn't necessarily faster/much faster than breaking down these operations in multiple loops. Looping a fixed amount of times over the input remains linear time complexity as well. You could try to both to see, but I would put more emphasis on layering than performance unless there's a bottleneck. Besides, if you don't already map the model to a view-model you probably will in the future anyway ;) – plalx May 18 '20 at 15:39
  • Mmmm I understand plalx and I think you are right. Finally in my project I was thinking and I had a conclusion. I set de url logo in the repository, when I mapping my domain object with dapper. Because I think is the best layer to do this in my project. – Mr.Beto May 20 '20 at 12:26
  • It could be fine. Just note that should you have to change the location for any reason you will have to update all DB records which is not ideal. – plalx May 20 '20 at 12:46
0

I would do it this way;

  • The domain concept "logo of a company" is the image , not the name of the image.

  • If you have a driven port for persisting company objects, then to store/retrieve the logo from the storage device (eg a database) is job of the adapter (infrastructure).

  • If you want to offer the image to clients via web, with an url, that's infrastructure too, the job of a driver adapter, a controller that deals with http.

choquero70
  • 3,332
  • 2
  • 24
  • 40