Note that there are some explanatory texts on larger screens.

plurals
  1. PODDD - Is a factory allowed to access a repository?
    primarykey
    data
    text
    <p>I'm having an aggregate-root called Person. The person also has an Address. The relation between these Classes is ManyToOne (Many Persons share the same Address). </p> <p>This means that when I'm creating a new Person with a specific address using a factory, I'd have to check if a same address already exists in the database and use an exisiting address for the user. </p> <p>This requires my factory to have access to an Address-Repository (or directly to the database). Is this allowed? And if not, what would be a better approach to do this?</p> <p>//EDIT My solution is now the following:</p> <p>I have a class PersonService which holds the logic to register a person. The method <code>register()</code> already takes an Address-Object which is created by an AddressFactory. The Addressfactory has access to an AddressRepository to check, whether the entered address already exists or not. Here's the code:</p> <pre><code>public class PersonService{ @Inject private PersonRepository pRepo; public Person register(Name name,..., Address address){ //check if same person exists, //create person, persist person return person; } } public class AddressFactory{ @Inject AddressRepository aRepo; public Address create(String street, int number, ...){ //check if address with attribues exists in repo, //if not create new address return address; } } </code></pre> <p>and in some bean this method is called like this:</p> <pre><code>personService.register(new Name("test"),..., addressFactory.create("Some street", 1,...)) </code></pre> <p>What do you think?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload