protected static void DuringRequest(ISlackServiceFactory services, Action <SlackRequestContext> duringRequest) { var requestListener = services.GetRequestListener(); var requestContext = new SlackRequestContext(); requestListener.OnRequestBegin(requestContext); duringRequest(requestContext); requestListener.OnRequestEnd(requestContext); }
protected static void DuringRequest(ISlackServiceProvider services, Action <SlackRequestContext> duringRequest) { var requestContext = new SlackRequestContext(); var requestScope = requestContext.BeginRequest(services.GetRequestListeners()); try { duringRequest(requestContext); } finally { requestScope.DisposeAsync().AsTask().ShouldComplete(); } }
public void OnRequestBegin(SlackRequestContext context) { if (context.ContainsKey("Envelope")) // Socket mode { var scope = _serviceProvider.CreateScope(); context.SetServiceProvider(scope.ServiceProvider); context.OnComplete(() => { scope.Dispose(); return(Task.CompletedTask); }); } else { context.SetServiceProvider(_httpContextAccessor.HttpContext.RequestServices); } }
public IAsyncWorkflowStepEditHandler CreateWorkflowStepEditHandler(SlackRequestContext context) => Resolve <IAsyncWorkflowStepEditHandler>(context);
public IAsyncViewSubmissionHandler CreateViewSubmissionHandler(SlackRequestContext context) => Resolve <IAsyncViewSubmissionHandler>(context);
public IOptionProvider CreateLegacyOptionProvider(SlackRequestContext context) => context.LifetimeScope().Resolve <IOptionProvider>();
public IEventHandler CreateEventHandler(SlackRequestContext context) => context.LifetimeScope().Resolve <IEventHandler>();
public IAsyncViewSubmissionHandler CreateViewSubmissionHandler(SlackRequestContext context) => context.LifetimeScope().Resolve <IAsyncViewSubmissionHandler>();
public IAsyncWorkflowStepEditHandler CreateWorkflowStepEditHandler(SlackRequestContext context) => context.LifetimeScope().Resolve <IAsyncWorkflowStepEditHandler>();
public static IServiceProvider ServiceProvider(this SlackRequestContext context) => context[ProviderKey] as IServiceProvider ?? throw new InvalidOperationException("Service scope missing from Slack request context");
public IBlockOptionProvider CreateBlockOptionProvider(SlackRequestContext context) => context.LifetimeScope().Resolve <IBlockOptionProvider>();
private static THandler Resolve <THandler>(SlackRequestContext context) => context.ServiceScope().ServiceProvider.GetRequiredService <THandler>();
public IEventHandler CreateEventHandler(SlackRequestContext context) => Resolve <IEventHandler>(context);
public IDialogSubmissionHandler CreateLegacyDialogSubmissionHandler(SlackRequestContext context) => Resolve <IDialogSubmissionHandler>(context);
public IOptionProvider CreateLegacyOptionProvider(SlackRequestContext context) => Resolve <IOptionProvider>(context);
public IInteractiveMessageHandler CreateLegacyInteractiveMessageHandler(SlackRequestContext context) => Resolve <IInteractiveMessageHandler>(context);
public void OnRequestBegin(SlackRequestContext context) { }
public static void SetServiceProvider(this SlackRequestContext context, IServiceProvider scopedProvider) => context[ProviderKey] = scopedProvider;
public IAsyncBlockActionHandler CreateBlockActionHandler(SlackRequestContext context) => context.LifetimeScope().Resolve <IAsyncBlockActionHandler>();
public static void SetContainerScope(this SlackRequestContext context, Scope scope) => context[ScopeKey] = scope;
public IAsyncGlobalShortcutHandler CreateGlobalShortcutHandler(SlackRequestContext context) => context.LifetimeScope().Resolve <IAsyncGlobalShortcutHandler>();
public static Scope ContainerScope(this SlackRequestContext context) => context[ScopeKey] as Scope ?? throw new InvalidOperationException("Container scope missing from Slack request context");
public IAsyncSlashCommandHandler CreateSlashCommandHandler(SlackRequestContext context) => context.LifetimeScope().Resolve <IAsyncSlashCommandHandler>();
public static void SetServiceScope(this SlackRequestContext context, IServiceScope scope) => context[ScopeKey] = scope;
public IInteractiveMessageHandler CreateLegacyInteractiveMessageHandler(SlackRequestContext context) => context.LifetimeScope().Resolve <IInteractiveMessageHandler>();
public IAsyncGlobalShortcutHandler CreateGlobalShortcutHandler(SlackRequestContext context) => Resolve <IAsyncGlobalShortcutHandler>(context);
public IDialogSubmissionHandler CreateLegacyDialogSubmissionHandler(SlackRequestContext context) => context.LifetimeScope().Resolve <IDialogSubmissionHandler>();
public SlackRequestContextScope(SlackRequestContext requestContext) => _requestContext = requestContext;
public static IServiceScope ServiceScope(this SlackRequestContext context) => context[ScopeKey] as IServiceScope ?? throw new InvalidOperationException("Service scope missing from Slack request context");
public IAsyncSlashCommandHandler CreateSlashCommandHandler(SlackRequestContext context) => Resolve <IAsyncSlashCommandHandler>(context);