mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.4 KiB
53 lines
1.4 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
|
|
namespace Squidex.Infrastructure.Commands
|
|
{
|
|
public sealed class CommandContext
|
|
{
|
|
private Tuple<object?>? result;
|
|
|
|
public Guid ContextId { get; } = Guid.NewGuid();
|
|
|
|
public ICommand Command { get; }
|
|
|
|
public ICommandBus CommandBus { get; }
|
|
|
|
public object? PlainResult
|
|
{
|
|
get { return result?.Item1; }
|
|
}
|
|
|
|
public bool IsCompleted
|
|
{
|
|
get { return result != null; }
|
|
}
|
|
|
|
public CommandContext(ICommand command, ICommandBus commandBus)
|
|
{
|
|
Guard.NotNull(command, nameof(command));
|
|
Guard.NotNull(commandBus, nameof(commandBus));
|
|
|
|
Command = command;
|
|
CommandBus = commandBus;
|
|
}
|
|
|
|
public CommandContext Complete(object? resultValue = null)
|
|
{
|
|
result = Tuple.Create(resultValue);
|
|
|
|
return this;
|
|
}
|
|
|
|
public T Result<T>()
|
|
{
|
|
return (T)result?.Item1!;
|
|
}
|
|
}
|
|
}
|