コード例 #1
0
ファイル: QkExtensions.cs プロジェクト: andrei-m-code/QkRest
        /// <summary>
        /// Configures and registers QkRest dependencies.
        /// </summary>
        public static void AddQkRest(this IServiceCollection services, Action <QkOptions> configurationAction = null)
        {
            if (!qkRestAdded)
            {
                var options = new QkOptions(services);

                configurationAction?.Invoke(options);

                if (!options.exceptionsConfigured)
                {
                    services.AddScoped <IQkExceptionHandler, QkExceptionHandler>();
                }

                if (options.authorizationConfigured)
                {
                    services.AddSingleton(typeof(IConfigureOptions <MvcOptions>), new QkMvcConfigureOptions(options));
                }

                if (!options.disableSwagger)
                {
                    services.AddSwaggerGen();
                    options.swaggerSetup.ForEach(services.ConfigureSwaggerGen);
                }

                qkRestAdded = true;
                return;
            }

            throw new InvalidOperationException(nameof(AddQkRest) + " should be called only once!");
        }
コード例 #2
0
 public QkMvcConfigureOptions(QkOptions qkOptions)
 {
     this.qkOptions = qkOptions;
 }