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.
51 lines
1.2 KiB
51 lines
1.2 KiB
// ==========================================================================
|
|
// CommandContext.cs
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex Group
|
|
// All rights reserved.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
|
|
namespace Squidex.Infrastructure.CQRS.Commands
|
|
{
|
|
public sealed class CommandContext
|
|
{
|
|
private readonly ICommand command;
|
|
private readonly Guid contextId = Guid.NewGuid();
|
|
private Tuple<object> result;
|
|
|
|
public ICommand Command
|
|
{
|
|
get { return command; }
|
|
}
|
|
|
|
public Guid ContextId
|
|
{
|
|
get { return contextId; }
|
|
}
|
|
|
|
public bool IsCompleted
|
|
{
|
|
get { return result != null; }
|
|
}
|
|
|
|
public CommandContext(ICommand command)
|
|
{
|
|
Guard.NotNull(command, nameof(command));
|
|
|
|
this.command = command;
|
|
}
|
|
|
|
public void Complete(object resultValue = null)
|
|
{
|
|
result = Tuple.Create(resultValue);
|
|
}
|
|
|
|
public T Result<T>()
|
|
{
|
|
return (T)result?.Item1;
|
|
}
|
|
}
|
|
}
|