using System.Configuration; using ASC.Api.Core; using ASC.Api.Core.Auth; using ASC.Api.Core.Core; using ASC.Api.Core.Middleware; using ASC.Common.Data; using ASC.Common.DependencyInjection; using ASC.Common.Logging; using ASC.Common.Security; using ASC.Common.Security.Authorizing; using ASC.Common.Utils; using ASC.Core; using ASC.Core.Billing; using ASC.Core.Caching; using ASC.Core.Common.Settings; using ASC.Core.Data; using ASC.Core.Notify; using ASC.Core.Security.Authorizing; using ASC.Core.Tenants; using ASC.Data.Reassigns; using ASC.Data.Storage.Configuration; using ASC.MessagingSystem; using ASC.Notify.Recipients; using ASC.Web.Core; using ASC.Web.Core.Notify; using ASC.Web.Core.Users; using ASC.Web.Core.Utility.Skins; using ASC.Web.Studio.Core.Notify; using ASC.Web.Studio.UserControls.Statistics; using ASC.Web.Studio.Utility; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; namespace ASC.People { public class Startup { public IConfiguration Configuration { get; } public IHostEnvironment HostEnvironment { get; } public Startup(IConfiguration configuration, IHostEnvironment hostEnvironment) { Configuration = configuration; HostEnvironment = hostEnvironment; } public void ConfigureServices(IServiceCollection services) { services.AddHttpContextAccessor(); services.AddControllers().AddControllersAsServices() .AddNewtonsoftJson() .AddXmlSerializerFormatters(); services.AddTransient, CustomJsonOptionsWrapper>(); services.AddMemoryCache(); services.AddDistributedMemoryCache(); services.AddSession(); services.AddAuthentication("cookie") .AddScheme("cookie", a => { }) .AddScheme("confirm", a => { }); var builder = services.AddMvc(config => { config.Filters.Add(new TypeFilterAttribute(typeof(TenantStatusFilter))); config.Filters.Add(new TypeFilterAttribute(typeof(PaymentFilter))); config.Filters.Add(new TypeFilterAttribute(typeof(IpSecurityFilter))); config.Filters.Add(new TypeFilterAttribute(typeof(ProductSecurityFilter))); config.Filters.Add(new CustomResponseFilterAttribute()); config.Filters.Add(new CustomExceptionFilterAttribute()); config.Filters.Add(new TypeFilterAttribute(typeof(FormatFilter))); config.OutputFormatters.RemoveType(); config.OutputFormatters.Add(new XmlOutputFormatter()); }); var container = services.AddAutofac(Configuration, HostEnvironment.ContentRootPath); services.AddLogManager() .AddStorage() .AddWebItemManager() .AddSingleton((r) => { var cs = DbRegistry.GetConnectionString("core"); if (cs == null) { throw new ConfigurationErrorsException("Can not configure CoreContext: connection string with name core not found."); } return (IUserService)new CachedUserService(new DbUserService(cs)); }) .AddSingleton((r) => { var cs = DbRegistry.GetConnectionString("core"); if (cs == null) { throw new ConfigurationErrorsException("Can not configure CoreContext: connection string with name core not found."); } return (ITenantService)new CachedTenantService(new DbTenantService(cs)); }) .AddSingleton((r) => { var quotaCacheEnabled = false; if (Common.Utils.ConfigurationManager.AppSettings["core:enable-quota-cache"] == null) { quotaCacheEnabled = true; } else { quotaCacheEnabled = !bool.TryParse(Common.Utils.ConfigurationManager.AppSettings["core:enable-quota-cache"], out var enabled) || enabled; } var cs = DbRegistry.GetConnectionString("core"); if (cs == null) { throw new ConfigurationErrorsException("Can not configure CoreContext: connection string with name core not found."); } return quotaCacheEnabled ? (IQuotaService)new CachedQuotaService(new DbQuotaService(cs)) : new DbQuotaService(cs); ; }) .AddSingleton((r) => { var cs = DbRegistry.GetConnectionString("core"); if (cs == null) { throw new ConfigurationErrorsException("Can not configure CoreContext: connection string with name core not found."); } return (ITariffService)new TariffService(cs, r.GetService(), r.GetService()); }) .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped() .AddScoped(typeof(IRecipientProvider), typeof(RecipientProviderImpl)) .AddSingleton(typeof(IRoleProvider), typeof(RoleProvider)) .AddScoped(typeof(IPermissionResolver), typeof(PermissionResolver)) .AddScoped(typeof(IPermissionProvider), typeof(PermissionProvider)) ; } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto }); app.UseCors(builder => builder .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod()); app.UseRouting(); app.UseSession(); app.UseAuthentication(); app.UseAuthorization(); app.UseCultureMiddleware(); app.UseDisposeMiddleware(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapCustom(); }); app.UseCSP(); app.UseCm(); app.UseStaticFiles(); } } }