How to pass parameters to my domain class methods

Asked

Viewed 34 times

0

Following the Patterns defined in the DDD I have my non-anemic domain class with data and behaviors and one of them is my aggregator, so far everything ok.

My question is when I have a lot of data that was passed by a user to create or update that entity my method gets many parameters.

One way to solve this would be to encapsulate these parameters in a class, but this class to be used in my domain would have to be part of it, but it gets weird to create this class when it doesn’t represent a value object, entity or anything similar being a simple DTO.

And I also don’t know if it’s right that I create one of these objects, as a value object outside of my aggregator, as far as I understand it’s his responsibility to create all the "children" that make up the same.

So is there any way to pass this list of parameters in a better way?

1 answer

0

I’m not sure I quite understand your question, but I think I can help. First of all about creating DTO, you can create a DTO whenever you feel it is necessary, because DTO is for that very purpose, to represent a structure that can be of a temporary data. It’s just a view of some data arranged in that structure. As I believe in the actual question, you have already answered. Instead of in the method signature you have to receive multiple parameters, you get a feathered array, containing N parameters. Ex: Instead of being this way(param1, param2, param3 ....) you would do so methodo(params[]) and within your method you would iterate 'params' and make the appropriate validations, and then the necessary manipulation

if I haven’t answered your question,?

  • In my view it makes no sense to create a DTO in my domain, summarizing my question would be whether there is an alternative in I create an Object value that belongs to an Aggregate outside of it to pass as parameter to my domain.

  • https://docs.microsoft.com/pt-br/dotnet/architecture/microservice-ddd-cqrs-patterns/net-core-microservice-domain-model Here’s an example where he adds a product to the cart but passes only the primitios leaving creation to the domain class, but in my case I have many attributes to pass, like a map and can’t pass without creating an object

Browser other questions tagged

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