Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            Secret secret = SecretManager.GetSecret();

            _logger = new LoggerConfiguration()
                      .WriteTo.Console()
                      .WriteTo.File("2falog.txt", rollingInterval: RollingInterval.Day)
                      .CreateLogger();

            IDocumentSession ravendb =
                RavenDbInitializer.Init(secret.RavenDbFilePath, secret.RavenDbServerUrl);

            services.AddTransient <IAuthFactor>(sp => {
                return(new SMSAuthFactorService(secret.TwilioAccountId, secret.TwilioAuthToken));
            });

            services.AddSingleton(typeof(Logger), _logger);

            services.AddSingleton(typeof(IDocumentSession), sp => { return(ravendb); });

            services.AddSingleton <IOTPCodeRepository>(sp => {
                return(new OTPCodeRepository(ravendb));
            });

            services.AddControllers();
        }
Ejemplo n.º 2
0
        private static IDocumentStore GetDocumentStore()
        {
            string appSetting = ConfigurationManager.AppSettings["RAVENHQ_CONNECTION_STRING"];

            var parser = ConnectionStringParser <RavenConnectionStringOptions> .FromConnectionString(appSetting);

            parser.Parse();

            string apiKey = parser.ConnectionStringOptions.ApiKey;
            string url    = parser.ConnectionStringOptions.Url;

            var documentStore = new DocumentStore {
                ApiKey = apiKey, Url = url
            };

            RavenDbInitializer.Initialize(documentStore);

            return(documentStore);
        }