예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LiteApiMiddleware"/> class.
        /// </summary>
        /// <param name="next">The next, provided by ASP.NET</param>
        /// <param name="options">The options, passed by <see cref="IApplicationBuilder"/> extension method.</param>
        /// <param name="services">The services, provided by ASP.NET</param>
        /// <exception cref="System.Exception">Middleware is already registered.</exception>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.ArgumentException">Assemblies with controllers is not passed to the LiteApiMiddleware</exception>
        public LiteApiMiddleware(RequestDelegate next, LiteApiOptions options, IServiceProvider services)
        {
            if (IsRegistered)
            {
                throw new Exception("Middleware is already registered.");
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            options.InternalServiceResolver.Initialize(services);

            if (options.ControllerAssemblies?.Count == 0)
            {
                throw new ArgumentException("Assemblies with controllers is not passed to the LiteApiMiddleware");
            }
            Options = options;
            if (options.LoggerFactory != null)
            {
                _logger           = new InternalLogger(true, options.LoggerFactory.CreateLogger <LiteApiMiddleware>());
                _isLoggingEnabled = true;
            }
            else
            {
                _logger = new InternalLogger(false, null);
            }
            // Services = services;
            _next        = next;
            IsRegistered = true;

            Initialize(services);
        }
예제 #2
0
 public static void SetLiteApiOptions(this HttpContext ctx, LiteApiOptions options)
 {
     ctx.Items[LiteApiOptionsKey] = options;
 }