Tengo una pregunta sobre DDD. Estoy compilando una aplicación para aprender DDD y tengo una pregunta sobre capas. Tengo una aplicación que funciona así:Definición de capas de aplicación en Domain-Driven-Design
llamadas capa de interfaz de usuario => Capa de aplicación -> Capa de Dominio -> base de datos
Aquí está un pequeño ejemplo de cómo se ve el código:
//****************UI LAYER************************
//Uses Ioc to get the service from the factory.
//This factory would be in the MyApp.Infrastructure.dll
IImplementationFactory factory = new ImplementationFactory();
//Interface and implementation for Shopping Cart service would be in MyApp.ApplicationLayer.dll
IShoppingCartService service = factory.GetImplementationFactory<IShoppingCartService>();
//This is the UI layer,
//Calling into Application Layer
//to get the shopping cart for a user.
//Interface for IShoppingCart would be in MyApp.ApplicationLayer.dll
//and implementation for IShoppingCart would be in MyApp.Model.
IShoppingCart shoppingCart = service.GetShoppingCartByUserName(userName);
//Show shopping cart information.
//For example, items bought, price, taxes..etc
...
//Pressed Purchase button, so even for when
//button is pressed.
//Uses Ioc to get the service from the factory again.
IImplementationFactory factory = new ImplementationFactory();
IShoppingCartService service = factory.GetImplementationFactory<IShoppingCartService>();
service.Purchase(shoppingCart);
//**********************Application Layer**********************
public class ShoppingCartService : IShoppingCartService
{
public IShoppingCart GetShoppingCartByUserName(string userName)
{
//Uses Ioc to get the service from the factory.
//This factory would be in the MyApp.Infrastructure.dll
IImplementationFactory factory = new ImplementationFactory();
//Interface for repository would be in MyApp.Infrastructure.dll
//but implementation would by in MyApp.Model.dll
IShoppingCartRepository repository = factory.GetImplementationFactory<IShoppingCartRepository>();
IShoppingCart shoppingCart = repository.GetShoppingCartByUserName(username);
//Do shopping cart logic like calculating taxes and stuff
//I would put these in services but not sure?
...
return shoppingCart;
}
public void Purchase(IShoppingCart shoppingCart)
{
//Do Purchase logic and calling out to repository
...
}
}
Parece que he puesto la mayoría de mis reglas comerciales en los servicios en lugar de los modelos y no estoy seguro de si esto es correcto. Además, no estoy completamente seguro si tengo la colocación correcta? ¿Tengo las piezas correctas en el lugar correcto? ¿También deberían mis modelos dejar mi modelo de dominio? En general, ¿estoy haciendo esto correctamente según DDD?
Gracias!
me queda bien !!! –