Where to create a Helpers layer?

Asked

Viewed 663 times

6

I need to create a layer Helpers which will contain classes that will be made available for the entire project. These classes will contain functions such as calculations, wipers of string, anyway, those functions we use all the time...

My project has the layers Presentation, Application, Domain, infra/Data, infra/crosscutting.

I thought I’d create the layer Helpers inside infra/crosscutting, is the right place?

  • In most of the projects I’ve worked on these types of class have always been at the Crosscutting/Infrastructure layer. And if they’re really used by all the layers then there’s no better place than this.

2 answers

5


Right or wrong in these things is relative. Everything works and in general is not falling apart. It is often precious to try to do so right so long as know what you’re doing. Without knowing even the right is not good.

I find your project too layered, but it’s just my general opinion.

In general it’s confusing to have helpers generic like this, but there are cases that are the best solution. We have no way to answer this.

It may be in helpers organize well, not become a heap of things. These helpers may be extension methods. Or they may be in some type that is not just one helper, perhaps even in an existing type. It can neither separate too much nor add too much.

Apart from that must put the helper, if it is appropriate to have one, in the place where it makes the most sense, it can be totally separated from the rest (for what it has gone through, it seems to be the case of almost everything) or it can be in one of these layers, depends on whether it is for use only in it. Don’t put something in a specific location and use it everywhere in the solution. Separate what is general library from the application. Not necessarily how helper.

3

Taking into account that your project already has these layers and you wanted to implement some helpers, one way to keep everything organized and respecting the layers would be to let the helper type determine which layer it will be on. If it is a helper that has to do with the database it will be in the infra layer, if it is a to format something in the UI it will be in the presentation layer and so on.

This is not a law, it is just a way to organize your helpers. You have to use the organization that pleases you most according to the project.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.