Persist/store in domain or application layer? - domain-driven-design

When creating a new entity, should the application service layer persist/attach it to the entity manager, the domain service layer or can even domain objects do this?

At the point where the new entity is created, the code that creates the entity should also register the new entity with the unit of work for persisting at the successful completion of that unit of work.

Related

How to communication between aggregate roots and split them into smaller parts?

Whole question was too long so this is edited shorter one. One of my aggregate roots handles projects and members in service A and other aggregate handles budgets and transactions in service B. To add transaction user must be a given project member. Can I ask a simplify member aggregate created in service B from domain events(MemberAdded/Removed) from service A if user is a member before modifying transactions aggregate? This simplify member aggregate would function as a domain service. Is it the DDD way of doing it and is it ok with CQRS to ask memberAggregate.IsMember() and then proceed to modify TranscationAggregate in single command?
My business model allows for delay between real state of service A Member aggregate and recreated simplify version in service B.
From what I understand if:
domain service is injected into aggregate root I'm losing domain logic purity
domain service is used in command I'm losing completeness because part of domain logic is outside of domain layer
if I remodel my domain to have members and transactions in single aggregate root I'm losing performance

How to add scheduled jobs in domain driven design

Which layer I should add scheduler project in domain driven design architecture?
I am thinking of adding scheduler in Distributed service layer and business login inside application services layer.
Here is the solution design I am thinking of:
Presentation Layer
UI project
Distribute Service Layer
Application API
Scheduler
Application Layer
Application (Application services for Application API and Scheduler logic)
DTO
Domain Entity Model
Project Domain (Domain entities specific to project)
Scheduler Domain (Domain entities specific to scheduler)
Data Persistence
Data Access Project (Repositories)
Data Access Scheduler Domain (Repositories)
Cross Cutting Infra.
Authorization
Logging
Any help is appreciated.
Since now I've implemented this kind of component in the Presentation layer, on the same level as the UI. These components are awaken by cronjobs at regular times then they call Application services in order to send commands to the Aggregates. Then, the Aggregates, if necessary and allowed, perform the changes to the system state.

Creating liferay service builder without configuring any database

Is it possible to create liferay service builder without any configuring any database tables in service.xml file.
Actually purpose here is to create a service layer using liferay service builder. And there is no database interaction directly in this service layer.
Yes, and it's quite simple. While you still need an entity (which provides the name for your service) you can leave this entity definition empty.
This will create the service (local or remote, as configured in the entity) but no model, no persistence and no database table.
One of the situations where this comes in really handy is when you want to add another method to an existing service (which you can't) - you just create a new service with your custom methods and delegate to the original service.
I agree with #Olaf Kock answare in which say that it is possible have an empty model with service builder. Furthermore have an empty entity you can benefit of have the same transactional context of your portal and benefit of cluster managing and benefit of a complete integration with liferay portal.
If you have the same transactional enviroment of the portal you can image of create a service that agregate native liferay service and you get the assurance that the transactional context is the same of the portal.
I hop that this reflection can add value.
Its highly recommended that If you're creating Service.xml then at least one entity should be there. Otherwise no need to add that configuration.
Able to create service builder without real entities.
As provided in the link it is possible to create service builder without entities.
Also discussed more in detail in this forum
Hope it helps some one. Thanks

MVC architecture like BAL, DAL and Presentation with EntityFramework?

I want to create a project in Asp.Net MVC with C# using Entity Framework with BAL and DAL layers ? There are two module here User and Admin module with custom login feature. Admin can add run time columns in the existing database with add, edit update the records such as any report.
The record display to the users.
If you have any such type of reference article/project (N-tier architecture) let us know please.
When i create MVC projects, i usually follow this structure:
UI Layer - This will be the actual mvc project and will interact with the service layer
Service Layer (BAL) - This will hold all your business logic classes and will interact with the data access layer. This layer will expose services the UI Layer can make use of
Data Access Layer - This will hold all classes related to data access. As you are using entity framework, your DbContext can live here
Entities - This will hold all entities used in your solution

In Domain Driven Design the factory classes can access to infraestructure?

If necessary, a factory can access elements of the infrastructure to build an object?. In a particular case, I have an object that I need to add email signature that is stored as a parameter in the configuration layer of the application.
In DDD, a Factory is at the same architectural level as a Repository, but for creating new objects instead of loading existing objects. So it can call infrastructure services just like the repository.
There is no one correct answer to this problem. If the factory itself is part of your application layer this should be fine. You can also add an application service that hands the email signature down into your domain when needed.

Resources