public static ICommandApplicationBuilder UseDefaultMiddlewares(this ICommandApplicationBuilder app)
        {
            app.UseDefaultExceptionMiddleware();
            app.UseStringMatcher();
            app.UseInputCountMatcher();
            app.UseParser();
            app.UseParamPreconditioner();
            app.UsePreconditioner();
            app.UseCommandExecutor();

            return(app);
        }
        /// <summary>
        /// Use Sentry integration
        /// </summary>
        /// <param name="app">The application.</param>
        /// <param name="registerSdkClose">Set it to <c>false</c> if this app is a Web ASP.NET Core app with the Sentry integration.</param>
        /// <returns></returns>
        public static ICommandApplicationBuilder UseSentry(this ICommandApplicationBuilder app, bool registerSdkClose = true)
        {
            // Container is built so resolve a logger and modify the SDK internal logger
            var options = app.ApplicationServices.GetService <IOptions <SentryMariCommandsOptions> >();

            if (options?.Value is SentryMariCommandsOptions o)
            {
                if (o.Debug && (o.DiagnosticLogger == null || o.DiagnosticLogger.GetType() == typeof(ConsoleDiagnosticLogger)))
                {
                    var logger = app.ApplicationServices.GetRequiredService <ILogger <ISentryClient> >();
                    o.DiagnosticLogger = new MelDiagnosticLogger(logger, o.DiagnosticsLevel);
                }

                var stackTraceFactory = app.ApplicationServices.GetService <ISentryStackTraceFactory>();
                if (stackTraceFactory != null)
                {
                    o.UseStackTraceFactory(stackTraceFactory);
                }

                if (app.ApplicationServices.GetService <IEnumerable <ISentryEventProcessor> >().Any())
                {
                    o.AddEventProcessorProvider(app.ApplicationServices.GetServices <ISentryEventProcessor>);
                }

                if (app.ApplicationServices.GetService <IEnumerable <ISentryEventExceptionProcessor> >().Any())
                {
                    o.AddExceptionProcessorProvider(app.ApplicationServices.GetServices <ISentryEventExceptionProcessor>);
                }
            }

            if (registerSdkClose)
            {
                var lifetime = app.ApplicationServices.GetService <IHostApplicationLifetime>();
                lifetime?.ApplicationStopped.Register(SentrySdk.Close);
            }

            return(app.UseMiddleware <SentryMiddleware>());
        }
        /// <summary>
        /// Add a middleware type to the command request pipeline.
        /// </summary>
        /// <param name="app">The current command aplication builder.</param>
        /// <param name="middlewareArgs">Additional ctor args for this middleware.</param>
        /// <returns>The current command aplication builder.</returns>
        public static ICommandApplicationBuilder UseMiddleware <TMiddleware>(this ICommandApplicationBuilder app, params object[] middlewareArgs)
            where TMiddleware : ICommandMiddleware
        {
            app.Use((next) =>
            {
                var types = middlewareArgs
                            ?.Select(a => a.GetType())
                            ?.ToArray() ?? new Type[0];

                var instanceFactory = ActivatorUtilities.CreateFactory(typeof(TMiddleware), types ?? Type.EmptyTypes);

                return(async context =>
                {
                    var instance = instanceFactory(context.CommandServices, middlewareArgs);

                    await(instance as ICommandMiddleware).InvokeAsync(context, next);

                    await MiddlewareUtils.SwitchDisposeAsync(instance);
                });
            });

            return(app);
        }
 public void ConfigureApp(ICommandApplicationBuilder app)
 {
     app.UseMiddleware <TestMiddleware>();
 }
 /// <summary>
 /// Use the default command executor middleware.
 /// </summary>
 /// <param name="app">The current command aplication builder.</param>
 /// <returns>The current command aplication builder.</returns>
 public static ICommandApplicationBuilder UseCommandExecutor(this ICommandApplicationBuilder app)
 => app.UseMiddleware <CommandExecutorMiddleware>();
 /// <summary>
 /// Use the default command preconditioner middleware.
 /// </summary>
 /// <param name="app">The current command aplication builder.</param>
 /// <returns>The current command aplication builder.</returns>
 public static ICommandApplicationBuilder UsePreconditioner(this ICommandApplicationBuilder app)
 => app.UseMiddleware <CommandPreconditionMiddleware>();
 /// <summary>
 /// Use the default command parser middleware.
 /// </summary>
 /// <param name="app">The current command aplication builder.</param>
 /// <returns>The current command aplication builder.</returns>
 public static ICommandApplicationBuilder UseParser(this ICommandApplicationBuilder app)
 => app.UseMiddleware <CommandParserMiddleware>();
 /// <summary>
 /// Use the default command input count matcher middleware.
 /// </summary>
 /// <param name="app">The current command aplication builder.</param>
 /// <returns>The current command aplication builder.</returns>
 public static ICommandApplicationBuilder UseInputCountMatcher(this ICommandApplicationBuilder app)
 => app.UseMiddleware <CommandInputCountMatcherMiddleware>();
 /// <summary>
 /// Use the default command string matcher middleware.
 /// </summary>
 /// <param name="app">The current command aplication builder.</param>
 /// <returns>The current command aplication builder.</returns>
 public static ICommandApplicationBuilder UseStringMatcher(this ICommandApplicationBuilder app)
 => app.UseMiddleware <CommandStringMatcherMiddleware>();
 /// <summary>
 /// Use the default Exception middleware that will just log the exception.
 /// </summary>
 /// <param name="app">The current command aplication builder.</param>
 /// <returns>The current command aplication builder.</returns>
 public static ICommandApplicationBuilder UseDefaultExceptionMiddleware(this ICommandApplicationBuilder app)
 => app.UseMiddleware <DefaultExceptionMiddleware>();
        public void ConfigureApp(ICommandApplicationBuilder app)
        {
            Assert.NotNull(app);

            app.Properties[LogKey] = LogValue;
        }
示例#12
0
 public void ConfigureApp(ICommandApplicationBuilder app)
 {
 }