/// <summary>
        /// Use gear app
        /// </summary>
        /// <param name="app"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public static IGearAppBuilder UseGearWebApp(this IApplicationBuilder app, Action <GearAppBuilderConfig> config)
        {
            var configuration = new GearAppBuilderConfig();

            config(configuration);

            using (var serviceScope = app.ApplicationServices
                                      .GetRequiredService <IServiceScopeFactory>()
                                      .CreateScope())
            {
                var sp          = serviceScope.ServiceProvider;
                var environment = sp.GetService <IHostingEnvironment>();
                GearWebApplication.IsConfigured(environment);

                var lifeTimeService = serviceScope.ServiceProvider.GetService <IApplicationLifetime>();
                lifeTimeService.RegisterAppEvents(app, configuration.AppName);

                //----------------------------------Localization Usage-------------------------------------

                var languages = serviceScope.ServiceProvider.GetService <IOptionsSnapshot <LocalizationConfig> >();
                app.UseLocalizationModule(languages);
            }

            if (GearApplication.IsHostedOnLinux())
            {
                app.UseForwardedHeaders(new ForwardedHeadersOptions
                {
                    ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
                });
            }

            if (configuration.HostingEnvironment.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            //-----------------------Custom url redirection Usage-------------------------------------
            if (configuration.UseCustomUrlRewrite)
            {
                app.UseUrlRewriteModule();
            }

            //----------------------------------Origin Cors Usage-------------------------------------
            if (configuration.UseDefaultCorsConfiguration)
            {
                app.UseConfiguredCors();
            }

            app.UseAuthentication()
            .UseIdentityServer();

            //custom rules
            app.UseAppMvc(configuration.Configuration, configuration.CustomMapRules);

            //--------------------------------------Swagger Usage-------------------------------------
            if (configuration.SwaggerConfiguration.UseSwaggerUI &&
                (configuration.SwaggerConfiguration.UseOnlyInDevelopment && configuration.HostingEnvironment.IsDevelopment() || !configuration.SwaggerConfiguration.UseOnlyInDevelopment))
            {
                app.UseSwagger()
                .UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint("/swagger/v1.0/swagger.json", "GEAR API v1.0");
                });
            }

            //----------------------------------Static files Usage-------------------------------------
            if (configuration.AppFileConfiguration.UseDefaultFiles)
            {
                app.UseDefaultFiles();
            }

            if (configuration.AppFileConfiguration.UseStaticFile)
            {
                app.UseStaticFiles();
            }

            //--------------------------------------Use compression-------------------------------------
            if (configuration.UseResponseCompression && configuration.HostingEnvironment.IsProduction())
            {
                app.UseResponseCompression();
            }


            //---------------------------------------SignalR Usage-------------------------------------
            if (configuration.SignlarAppConfiguration.UseDefaultSignlarConfiguration)
            {
                app.UseSignalRModule(configuration.SignlarAppConfiguration.Path);
            }

            return(new GearAppBuilder(app.ApplicationServices));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="hostingEnvironment"></param>
 /// <param name="configuration"></param>
 /// <param name="installerService"></param>
 public InstallerController(IHostingEnvironment hostingEnvironment, IConfiguration configuration, IGearWebInstallerService installerService)
 {
     _configuration    = configuration;
     _installerService = installerService;
     _isConfigured     = GearWebApplication.IsConfigured(hostingEnvironment);
 }