Example #1
0
        public static ItemCreated Handle(
            // This would be the message
            CreateItemCommand command,

            // Any other arguments are assumed
            // to be service dependencies
            ItemsDbContext db)
        {
            // Create a new Item entity
            var item = new Item
            {
                Name = command.Name
            };

            // Add the item to the current
            // DbContext unit of work
            db.Items.Add(item);

            // This event being returned
            // by the handler will be automatically sent
            // out as a "cascading" message
            return(new ItemCreated
            {
                Id = item.Id
            });
        }
Example #2
0
        public string GetItems([FromServices] ItemsDbContext context)
        {
            var items = context.Items.AsQueryable().ToList();

            if (items.Any())
            {
                var text = items.Select(x => x.Name).Join("\n");

                return($"The items are:\n{text}");
            }
            else
            {
                return("There are no persisted items yet");
            }
        }
 public DoItAllMyselfItemController(IMessageContext messaging, ItemsDbContext db)
 {
     _messaging = messaging;
     _db        = db;
 }