private static T CreateHandler <T>(SlackRequestContext context, Func <SlackRequestContext, T> handlerFactory) { if (context.ContainsKey(RequestHandler)) { throw new InvalidOperationException("Handler already created for this request"); } var handler = handlerFactory(context); context[RequestHandler] = handler; return(handler); }
private static T GetOrCreateHandler <T>(SlackRequestContext context, Func <T> handlerFactory) { if (!(context[RequestHandlers] is Dictionary <Type, object> instances)) { context[RequestHandlers] = instances = new Dictionary <Type, object>(); } if (!instances.TryGetValue(typeof(T), out var handler)) { instances[typeof(T)] = handler = handlerFactory(); } return((T)handler); }
public IDialogSubmissionHandler CreateLegacyDialogSubmissionHandler(SlackRequestContext context) => GetOrCreateHandler(context, _legacyDialogSubmissionHandler);
public IOptionProvider CreateLegacyOptionProvider(SlackRequestContext context) => GetOrCreateHandler(context, _legacyOptionProvider);
public IInteractiveMessageHandler CreateLegacyInteractiveMessageHandler(SlackRequestContext context) => GetOrCreateHandler(context, _legacyInteractiveMessageHandler);
public IAsyncWorkflowStepEditHandler CreateWorkflowStepEditHandler(SlackRequestContext context) => GetOrCreateHandler(context, _workflowStepEditHandler);
public IAsyncSlashCommandHandler CreateSlashCommandHandler(SlackRequestContext context) => GetOrCreateHandler(context, _slashCommandHandler);
public IAsyncViewSubmissionHandler CreateViewSubmissionHandler(SlackRequestContext context) => GetOrCreateHandler(context, _viewSubmissionHandler);
public IAsyncGlobalShortcutHandler CreateGlobalShortcutHandler(SlackRequestContext context) => GetOrCreateHandler(context, _globalShortcutHandler);
public IAsyncMessageShortcutHandler CreateMessageShortcutHandler(SlackRequestContext context) => GetOrCreateHandler(context, _messageShortcutHandler);
public IBlockOptionProvider CreateBlockOptionProvider(SlackRequestContext context) => GetOrCreateHandler(context, _blockOptionProvider);
public IAsyncBlockActionHandler CreateBlockActionHandler(SlackRequestContext context) => GetOrCreateHandler(context, _blockActionHandler);
public IEventHandler CreateEventHandler(SlackRequestContext context) => GetOrCreateHandler(context, _eventHandler);
public HandlerCollection(SlackRequestContext context, IEnumerable <Func <SlackRequestContext, T> > handlerFactories) =>
public HandlerIndex(SlackRequestContext requestContext, IReadOnlyDictionary <string, Func <SlackRequestContext, THandler> > handlers) =>