Ejemplo n.º 1
0
        /// <summary>
        /// Adds services to the container.
        /// </summary>
        public void ConfigureServices(IServiceCollection services)
        {
            log.LogDebug("Configuring services...");

            // Ignore antiforgery tokens
            services.AddMvc().AddRazorPagesOptions(o =>
            {
                o.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute());
            });

            // Load application settings
            var settingsRawData = File.ReadAllText("appsettings.json");

            if (settingsRawData == null)
            {
                log.LogCritical("Failed to load appsettings.json");
                Environment.Exit(1);
            }

            // Create user database service
            var           settings = (JObject)JsonConvert.DeserializeObject(settingsRawData);
            UsersDatabase usersDb  = new UsersDatabase(settings["ConnectionStrings"]["Users"].Value <string>(), logFactory);

            if (!usersDb.Open())
            {
                log.LogCritical("Failed to connect to users database");
                Environment.Exit(1);
            }

            // Create email service
            if (!File.Exists("EmailTemplate.json"))
            {
                log.LogCritical("Failed to load email template.");
                Environment.Exit(1);
            }

            string       htmlTemplate = File.ReadAllText("EmailTemplate.json");
            EmailService emailService = new EmailService(settings["Keys"]["MailjetAPI"].Value <string>(),
                                                         settings["Keys"]["MailjetSecret"].Value <string>(), htmlTemplate, logFactory);

            // Create attom data service for house estimates
            AttomData attomDataService = new AttomData(settings["Keys"]["Attom"].Value <string>(), logFactory);

            // Add built-in services
            // Add HttpContextAccessor for IP retrieval
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            // Add custom services
            services.AddSingleton(logFactory);
            services.AddSingleton(usersDb);
            services.AddSingleton(emailService);
            services.AddSingleton(attomDataService);
        }
Ejemplo n.º 2
0
 public QuoteModel(UsersDatabase usersDatabase, AttomData aData)
 {
     this.usersDatabase = usersDatabase;
     this.aData         = aData;
 }