DEV Community

Discussion on: Introducing Gate Classes (Design Pattern)

Collapse
 
glenmccallumcan profile image
Glen McCallum

First time I've seen this! Can't wait to try it out.

Collapse
 
jamesmh profile image
James Hickey

Let me know when you do 👍 It's been working well for me!

Collapse
 
glenmccallumcan profile image
Glen McCallum

Where do you put your gate classes in your project package/folder structure?

Thread Thread
 
jamesmh profile image
James Hickey

Usually, I have a project structure like:

web (app layer) -> use cases -> domain project

I tend to put all these kinds of classes in the use cases project. I'll have a structure using feature folders something like:

  • Features
    • Orders
    • Payments
    • Shipping

For cross-cutting stuff like checking a user's role, etc. I would create another folder in the root of the use case projects called "Gates".

If a specific gate class is really tied to a specific feature of the application, which is rare since they are mostly useful for cross-cutting kinds of concerns like checking user permissions etc., then I would just make a "Gates" folder in the features folder:

  • Orders
    • Gates (folder)
    • PlaceStandardOrderCommand.cs (use case)
    • GetActiveOrderForUserQuery.cs (use case)
    • ...and more use cases...