private void CreateDatabaseIfNotExists()
        {
            var database = Store.Database;
            var dbRecord = Store.Admin.Server.Send(new GetDatabaseRecordOperation(database));

            if (dbRecord == null)
            {
                this._logger.LogInformation("RavenDB database does not exist, creating and seeding with initial data");

                // Create database
                dbRecord = new DatabaseRecord(database);

                var createResult = Store.Admin.Server.Send(new CreateDatabaseOperation(dbRecord));

                if (createResult.Name != null)
                {
                    // Seed database
                    var talks    = CsvData.LoadTalks();
                    var speakers = CsvData.LoadSpeakers();

                    // old => new speaker ID map
                    var speakerIdMap = new Dictionary <string, string>();

                    using (var session = Store.OpenSession())
                    {
                        foreach (var speaker in speakers)
                        {
                            var oldId = speaker.Id;
                            speaker.Id = null;
                            session.Store(speaker);
                            speakerIdMap.Add(oldId, speaker.Id);
                        }

                        foreach (var talk in talks)
                        {
                            talk.Id      = null;
                            talk.Speaker = speakerIdMap[talk.Speaker];
                            session.Store(talk);
                        }
                        session.SaveChanges();
                    }

                    this._logger.LogInformation("Seeded database with {0} talks", talks.Count);
                    this._logger.LogInformation("Seeded database with {0} speakers", speakers.Count);
                }
            }
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();
            services.AddMvc();
            services.AddLogging();

            // Configure RavenDB options and store holder
            services.Configure <RavenSettings>(Configuration.GetSection("Raven"));
            services.AddSingleton <IDocumentStoreHolder, DocumentStoreHolder>();

            // Configure talk data services
            services.AddSingleton <InMemoryTalkService, InMemoryTalkService>();
            services.AddTransient <RavenTalkService, RavenTalkService>();
            services.AddTransient <TalkServiceProvider, TalkServiceProvider>();

            // Static load
            InMemoryTalkService.Load(CsvData.LoadTalks(), CsvData.LoadSpeakers());
        }