// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var diHelper = new DIHelper(services); services.AddHttpContextAccessor(); services.AddMemoryCache(); services.AddControllers() .AddJsonOptions(options => { options.JsonSerializerOptions.WriteIndented = false; options.JsonSerializerOptions.IgnoreNullValues = true; }); services.AddMemoryCache(); diHelper.TryAdd(typeof(ICacheNotify <>), typeof(KafkaCache <>)); diHelper.TryAdd <AuthHandler>(); diHelper.TryAdd <CalDavController>(); diHelper.TryAdd <CoreSettingsController>(); diHelper.TryAdd <PortalController>(); diHelper.TryAdd <RegistrationController>(); diHelper.TryAdd <SettingsController>(); diHelper.TryAdd <TariffController>(); services.AddAuthentication() .AddScheme <AuthenticationSchemeOptions, AuthHandler>("auth.allowskip", _ => { }) .AddScheme <AuthenticationSchemeOptions, AuthHandler>("auth.allowskip.registerportal", _ => { }); LogNLogExtension.ConfigureLog(diHelper, "ASC.Apisystem"); }
public static async Task Main(string[] args) { var host = Host.CreateDefaultBuilder(args) .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureAppConfiguration((hostContext, config) => { var buided = config.Build(); var path = buided["pathToConf"]; if (!Path.IsPathRooted(path)) { path = Path.GetFullPath(Path.Combine(hostContext.HostingEnvironment.ContentRootPath, path)); } config.SetBasePath(path); var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production"); config .AddJsonFile("appsettings.json") .AddJsonFile($"appsettings.{env}.json", true) .AddJsonFile($"appsettings.services.json", true) .AddJsonFile("storage.json") .AddJsonFile("notify.json") .AddJsonFile("kafka.json") .AddJsonFile($"kafka.{env}.json", true) .AddEnvironmentVariables() .AddCommandLine(args) .AddInMemoryCollection(new Dictionary <string, string> { { "pathToConf", path } } ); }) .ConfigureServices((hostContext, services) => { services.AddMemoryCache(); var diHelper = new DIHelper(services); diHelper.TryAdd(typeof(ICacheNotify <>), typeof(KafkaCache <>)); LogNLogExtension.ConfigureLog(diHelper, "ASC.Notify", "ASC.Notify.Messages"); services.AddHostedService <ServiceLauncher>(); diHelper.TryAdd <ServiceLauncher>(); NotifyConfigurationExtension.Register(diHelper); diHelper.TryAdd <EmailSenderSink>(); }) .ConfigureContainer <ContainerBuilder>((context, builder) => { builder.Register(context.Configuration, context.HostingEnvironment.ContentRootPath); }) .UseConsoleLifetime() .Build(); using (host) { // Start the host await host.StartAsync(); // Wait for the host to shutdown await host.WaitForShutdownAsync(); } }
public void ConfigureServices(IServiceCollection services) { var diHelper = new DIHelper(services); services.AddLogging(); diHelper.Configure(services); services.AddSingleton(Configuration); diHelper.TryAdd <ProgramScope>(); LogNLogExtension.ConfigureLog(diHelper); }
public virtual void ConfigureServices(IServiceCollection services) { services.AddHttpContextAccessor(); services.AddMemoryCache(); DIHelper.Configure(services); if (AddControllers) { services.AddControllers() .AddXmlSerializerFormatters() .AddJsonOptions(options => { options.JsonSerializerOptions.WriteIndented = false; options.JsonSerializerOptions.IgnoreNullValues = true; options.JsonSerializerOptions.Converters.Add(new ApiDateTimeConverter()); if (Converters != null) { foreach (var c in Converters) { options.JsonSerializerOptions.Converters.Add(c); } } }); } DIHelper.TryAdd <DisposeMiddleware>(); DIHelper.TryAdd <CultureMiddleware>(); DIHelper.TryAdd <IpSecurityFilter>(); DIHelper.TryAdd <PaymentFilter>(); DIHelper.TryAdd <ProductSecurityFilter>(); DIHelper.TryAdd <TenantStatusFilter>(); DIHelper.TryAdd <ConfirmAuthHandler>(); DIHelper.TryAdd(typeof(ICacheNotify <>), typeof(KafkaCache <>)); var builder = services.AddMvcCore(config => { var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build(); config.Filters.Add(new AuthorizeFilter(policy)); 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 <XmlSerializerOutputFormatter>(); config.OutputFormatters.Add(new XmlOutputFormatter()); }); var authBuilder = services.AddAuthentication("cookie") .AddScheme <AuthenticationSchemeOptions, CookieAuthHandler>("cookie", a => { }); if (ConfirmAddScheme) { authBuilder.AddScheme <AuthenticationSchemeOptions, ConfirmAuthHandler>("confirm", a => { }); } if (LogParams != null) { LogNLogExtension.ConfigureLog(DIHelper, LogParams); } }