示例#1
0
        protected PostModule(IUnitOfWork unitOfWork, ICommandHandler <TMessage> commandHandler, string path,
                             NHibernateUnitOfWork relationalUnitOfWork, EventDispatcher eventDispatcher)
        {
            this.unitOfWork           = unitOfWork;
            this.commandHandler       = commandHandler;
            this.relationalUnitOfWork = relationalUnitOfWork;
            this.eventDispatcher      = eventDispatcher;

            this.RequiresAuthentication();
            this.RequiresHttps();

            Post[path] = _ =>
            {
                CustomUserIdentity user = this.Context.CurrentUser as CustomUserIdentity;

                TMessage message = this.Bind <TMessage>();
                message.UserId    = user.Id;
                message.ProcessId = Guid.NewGuid();

                EResultCode resultCode = default(EResultCode);
                unitOfWork.DoInTransaction(() =>
                {
                    resultCode = (EResultCode)commandHandler.Handle(message);
                });

                relationalUnitOfWork.DoInTransaction(eventDispatcher.DispatchEvents);


                return(new Response()
                {
                    StatusCode = (HttpStatusCode)resultCode,
                });
            };
        }