Пример #1
0
        public static LambdaExpression ParseLambda(IDynamicLinkCustomTypeProvider provider, ParameterExpression[] parameters, Type resultType, string expression, params object[] values)
        {
            ExpressionParser parser = new ExpressionParser(provider, parameters, expression, values);

            return(Expression.Lambda(parser.Parse(resultType), parameters));
        }
Пример #2
0
 public static LambdaExpression ParseLambda(IDynamicLinkCustomTypeProvider provider, Type itType, Type resultType, string expression, params object[] values)
 {
     return(ParseLambda(provider, new ParameterExpression[] { Expression.Parameter(itType, "") }, resultType, expression, values));
 }
Пример #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IHostApplicationLifetime appLifetime,
                              IDynamicLinkCustomTypeProvider dynamicLinkCustomTypeProvider,
                              ISecretsManager secretsManager)
        {
            // Secrets
            Settings.Get <JwtSettings>().SecretKey = secretsManager.Get(JwtSettings.ConfigKey);

            // Configurations
            app.RegisterOptionsChangeHandlers(typeof(AppSettings),
                                              typeof(JwtSettings));

            // AutoMapper
            var mapConfig = new MapperConfiguration(cfg =>
            {
                cfg.AddMaps(StartupConfig.TempAssemblyList);
            });

            GlobalMapper.Init(mapConfig.CreateMapper());

            // Dynamic Linq
            DynamicLinqConsts.DefaultParsingConfig = new ParsingConfig
            {
                CustomTypeProvider = dynamicLinkCustomTypeProvider
            };

            // HttpContext
            app.ConfigureHttpContext();

            #region Serilog
            if (!_requestLoggingOptions.UseDefaultLogger)
            {
                var requestLogger = Configuration.ParseLogger(
                    LoggingConsts.RequestLoggingOptionsKey, app.ApplicationServices);
                app.UseDefaultSerilogRequestLogging(_requestLoggingOptions, requestLogger);
                _resources.Add(requestLogger);
            }
            else
            {
                app.UseDefaultSerilogRequestLogging(_requestLoggingOptions);
            }
            #endregion

            app.UseExceptionHandler($"/{Routing.Controller.Error.Route}");

            app.UseRequestFeature();

            app.UseStaticFiles();

            app.UseHttpsRedirection();

            app.UseRequestLocalization();

            app.UseRouting();

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();
            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
                c.RoutePrefix = string.Empty;
                c.InjectStylesheet("/custom-swagger-ui.css");
            });

            app.UseCors(builder =>
            {
                builder.AllowAnyHeader();
                builder.AllowAnyMethod();
                builder.AllowCredentials();
                //builder.AllowAnyOrigin();
                builder.SetIsOriginAllowed(origin =>
                {
                    return(true);
                });
            });

            app.UseAuthentication();

            app.UseRequestDataExtraction();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            // app lifetime
            appLifetime.ApplicationStarted.Register(OnApplicationStarted);
            appLifetime.ApplicationStopped.Register(OnApplicationStopped);

            PrepareEnvironment(env);
        }
Пример #4
0
 public DefaultDynamicLinqCustomTypeProviderTests()
 {
     _sut = new DefaultDynamicLinqCustomTypeProvider();
 }
Пример #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IHostApplicationLifetime appLifetime,
                              IDynamicLinkCustomTypeProvider dynamicLinkCustomTypeProvider,
                              ISecretsManager secretsManager)
        {
            // Secrets
            Settings.SecretsManager = secretsManager;
            Settings.Jwt.SecretKey  = secretsManager.Get(JwtSettings.ConfigKey);

            // Configurations
            app.RegisterOptionsChangeHandlers(typeof(AppSettings),
                                              typeof(JwtSettings),
                                              typeof(ApiSettings));

            // AutoMapper
            var mapConfig = new MapperConfiguration(cfg =>
            {
                cfg.AddMaps(_tempAssemblyList);
            });

            GlobalMapper.Init(mapConfig.CreateMapper());

            // Dynamic Linq
            DynamicLinqEntityTypeProvider.DefaultParsingConfig = new ParsingConfig
            {
                CustomTypeProvider = dynamicLinkCustomTypeProvider
            };

            // i18n
            Time.Providers.Default      = Time.Providers.Utc;
            Time.ThreadTimeZoneProvider = new HttpThreadTimeZoneProvider();

            // HttpContext
            app.ConfigureHttpContext();

            // BusinessContext
            app.ConfigureBusinessContext();

            // UnitOfWork
            app.ConfigureUnitOfWork();

            PrepareEnvironment(env);

            if (env.IsDevelopment())
            {
                // configure dev settings
            }

            #region Serilog
            if (!_requestLoggingOptions.UseDefaultLogger)
            {
                _requestLogger = Configuration.ParseLogger(
                    ConfigConsts.Logging.RequestLoggingOptionsKey, app.ApplicationServices);
            }

            app.UseDefaultSerilogRequestLogging(_requestLoggingOptions, _requestLogger);
            #endregion

            app.UseExceptionHandler($"/{ApiEndpoint.Error}");

            app.UseRequestFeature();

            app.UseStaticFiles();

            app.UseHttpsRedirection();

            app.UseRequestLocalization();

            app.UseRouting();

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();
            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
                c.RoutePrefix = string.Empty;
            });

            app.UseCors(builder =>
            {
                builder.AllowAnyHeader();
                builder.AllowAnyMethod();
                builder.AllowCredentials();
                //builder.AllowAnyOrigin();
                builder.SetIsOriginAllowed(origin =>
                {
                    return(true);
                });
            });

            app.UseRequestTimeZone();

            app.UseAuthentication();

            app.UseRequestDataExtraction();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            // app lifetime
            appLifetime.ApplicationStarted.Register(OnApplicationStarted);
            appLifetime.ApplicationStopped.Register(OnApplicationStopped);
        }