-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
936 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using SlackNet.Blocks; | ||
using SlackNet.Interaction; | ||
|
||
namespace SlackNet.AspNetCore | ||
{ | ||
class ResolvedBlockActionHandler<TAction, THandler> : IBlockActionHandler<TAction> | ||
where TAction : BlockAction | ||
where THandler : IBlockActionHandler<TAction> | ||
{ | ||
private readonly IServiceProvider _serviceProvider; | ||
public ResolvedBlockActionHandler(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider; | ||
|
||
public async Task Handle(TAction action, BlockActionRequest request) | ||
{ | ||
using (var scope = _serviceProvider.CreateScope()) | ||
{ | ||
var handler = scope.ServiceProvider.GetRequiredService<THandler>(); | ||
await handler.Handle(action, request).ConfigureAwait(false); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using SlackNet.Interaction; | ||
|
||
namespace SlackNet.AspNetCore | ||
{ | ||
abstract class ResolvedBlockOptionProvider : IBlockOptionProvider | ||
{ | ||
protected ResolvedBlockOptionProvider(string actionId) => ActionName = actionId; | ||
|
||
public string ActionName { get; } | ||
|
||
public abstract Task<BlockOptionsResponse> GetOptions(BlockOptionsRequest request); | ||
} | ||
|
||
class ResolvedBlockOptionProvider<T> : ResolvedBlockOptionProvider | ||
where T : IBlockOptionProvider | ||
{ | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
public ResolvedBlockOptionProvider(IServiceProvider serviceProvider, string actionId) | ||
: base(actionId) | ||
{ | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
public override Task<BlockOptionsResponse> GetOptions(BlockOptionsRequest request) | ||
{ | ||
var handler = _serviceProvider.GetRequiredService<T>(); | ||
return handler.GetOptions(request); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using SlackNet.Blocks; | ||
using SlackNet.Interaction; | ||
|
||
namespace SlackNet.AspNetCore | ||
{ | ||
class SlackBlockActionsService : ISlackBlockActions | ||
{ | ||
private readonly SlackBlockActions _slackBlockActions = new SlackBlockActions(); | ||
|
||
public SlackBlockActionsService(IEnumerable<IBlockActionHandler> handlers) | ||
{ | ||
foreach (var handler in handlers) | ||
AddHandler((dynamic)handler); | ||
} | ||
|
||
public Task Handle(BlockActionRequest request) => _slackBlockActions.Handle(request); | ||
|
||
public void AddHandler<TAction>(IBlockActionHandler<TAction> handler) where TAction : BlockAction => _slackBlockActions.AddHandler(handler); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using SlackNet.Interaction; | ||
|
||
namespace SlackNet.AspNetCore | ||
{ | ||
class SlackBlockOptionsService : ISlackBlockOptions | ||
{ | ||
private readonly ISlackBlockOptions _options = new SlackBlockOptions(); | ||
|
||
public SlackBlockOptionsService(IEnumerable<ResolvedBlockOptionProvider> providers) | ||
{ | ||
foreach (var provider in providers) | ||
_options.SetProvider(provider.ActionName, provider); | ||
} | ||
|
||
public Task<BlockOptionsResponse> Handle(BlockOptionsRequest request) => _options.Handle(request); | ||
public void SetProvider(string actionId, IBlockOptionProvider handler) => _options.SetProvider(actionId, handler); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.