コード例 #1
0
ファイル: ItemHandler.cs プロジェクト: pkoronawa/jasper
        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
            });
        }
コード例 #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");
            }
        }
コード例 #3
0
 public DoItAllMyselfItemController(IMessageContext messaging, ItemsDbContext db)
 {
     _messaging = messaging;
     _db        = db;
 }