Conversation
It's now possible to inject scoped services in the module constructor. It's also possible to make a custom parameter provider with IParameterProvider.
velddev
left a comment
There was a problem hiding this comment.
Lets some questions and remarks
|
|
||
| public CommandTree Create(Assembly assembly) | ||
|
|
||
| public IServiceCollection Services { get; } |
There was a problem hiding this comment.
Why are these public now? they shouldn't be used externally.
There was a problem hiding this comment.
So you can easily add services when you make an extension method, e.g.:
public static class CommandExtensions
{
public static CommandTreeBuilder AddWarningsModule(this CommandTreeBuilder builder)
{
builder.Services.AddScoped<IWarningService, WarningService>();
builder.AddAssembly(typeof(CommandExtensions).Assembly);
return builder;
}
}Now you can call the extension method AddWarningsModule and all the required services are added:
services.AddCommands(builder =>
{
builder.AddWarningsModule();
});|
|
||
| namespace Miki.Framework.Commands | ||
| { | ||
| internal class CommandTreeCompiler |
There was a problem hiding this comment.
Can we perhaps have any test cases for this?
| .ToList(); | ||
|
|
||
| private MemberInfo Type { get; } | ||
| public Type Type { get; } |
There was a problem hiding this comment.
This was needed when the delegate is being compiled, I need the parent type when creating the NodeExecutable:
| } | ||
| catch (Exception e) | ||
| { | ||
| Log.Error(e); |
There was a problem hiding this comment.
No, this is after the pipeline. This is called when an exception occurred in the middelware.
There was a problem hiding this comment.
Can we add an event then when an exception occurs to fetch the current context state and exception?
| public interface IContext | ||
| { | ||
| /// <summary> | ||
| /// The message received from discord. |
There was a problem hiding this comment.
"The message recieved from Discord" is deceiving, it will change into more providers in the future.
| throw new ArgumentNullException(nameof(handler)); | ||
| } | ||
|
|
||
| app.Use(_ => handler); |
There was a problem hiding this comment.
The extension method .Run is being used at the end of the pipeline, so you don't need the next middleware. This is the same as ASP.NET Core.
| /// <returns></returns> | ||
| public static IBotApplicationBuilder UseWhen(this IBotApplicationBuilder app, Predicate predicate, Action<IBotApplicationBuilder> configuration) | ||
| { | ||
| if (app == null) |
There was a problem hiding this comment.
App can't be null here right? Either way, you can use Required<IBotApplicationBuilder> to automate the process.
There was a problem hiding this comment.
App can't be null here right?
Probably not, this is how Microsoft implemented UseWhen as well but I can remove this.
Either way, you can use Required to automate the process.
Required<IBotApplicationBuilder> is not possible because it's an extension method. It would register the extension method to Required<IBotApplicationBuilder> instead of IBotApplicationBuilder.
There was a problem hiding this comment.
Fair enough, but the other params could have it set to required.
| public static IServiceCollection AddCacheClient<T>(this IServiceCollection services) | ||
| where T : class, IExtendedCacheClient | ||
| { | ||
| services.AddSingleton<ICacheClient>(provider => provider.GetService<IExtendedCacheClient>()); |
There was a problem hiding this comment.
IExtendedCacheClient extends ICacheClient. This registration redirects ICacheClient to IExtendedCacheClient, you could register it two times but that means you have (for example) two Redis connections open.
There was a problem hiding this comment.
That doesn't make sense, we already have connection pooling.
This PR adds Microsoft.Extensions.Hosting support to Miki.Framework. This makes it way easier to set-up a new bot in a console application or even a ASP.NET Core application.
Middlewares
This PR introduces
IBotApplicationBuilderwhich is equal to IApplicationBuilder in ASP.Net Core.You can define middlewares in
ConfigureBot:Command pipeline
To use a command stage in the new middleware, you can use
app.UseStage<ClassName>().To use the
CommandPipelineBuilderextensions, you can useapp.UsePipeline:Example bot