using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Raven.Client.Documents; using Raven.Client.Http; namespace zero.Persistence; internal class ZeroPersistenceModule : ZeroModule { public override void ConfigureServices(IServiceCollection services, IConfiguration configuration) { services.AddSingleton(); services.AddSingleton(CreateRavenStore); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddOptions().Bind(configuration.GetSection("Zero:Raven")); } /// /// Creates and configures the raven store /// protected ZeroDocumentStore CreateRavenStore(IServiceProvider services) { IZeroOptions options = services.GetService(); IZeroDocumentConventionsBuilder conventionsBuilder = services.GetService(); IZeroDocumentStore store = new ZeroDocumentStore(options) { Urls = new string[1] { options.For().Url }, Conventions = { AggressiveCache = { Duration = TimeSpan.FromHours(1), Mode = AggressiveCacheMode.TrackChanges } } }; conventionsBuilder.Run(store.Conventions); IDocumentStore raven = store.Initialize(); // create all indexes if (options.Initialized) { //var indexes = options.Raven.Indexes.BuildAll(options, store); //IndexCreation.CreateIndexes(indexes, store, database: options.Raven.Database); } return (ZeroDocumentStore)raven; } }