IDocumentStore => IZeroStore

This commit is contained in:
2020-11-15 17:07:27 +01:00
parent 3943f92f4c
commit c4e91efd5b
33 changed files with 155 additions and 164 deletions
+5 -6
View File
@@ -1,13 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Raven.Client.Documents;
using Raven.Client.Documents.Session;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using zero.Core.Api;
using zero.Core.Database;
using zero.Core.Entities;
using zero.Core.Extensions;
using zero.Core.Routing;
using zero.Web.Models;
@@ -16,14 +15,14 @@ namespace zero.Web.Controllers
public class PagesController : BackofficeController
{
IPagesApi Api;
IDocumentStore Raven;
IZeroStore Store;
IRevisionsApi RevisionsApi;
public PagesController(IPagesApi api, IRevisionsApi revisionsApi, IDocumentStore raven)
public PagesController(IPagesApi api, IRevisionsApi revisionsApi, IZeroStore store)
{
Api = api;
RevisionsApi = revisionsApi;
Raven = raven;
Store = store;
}
@@ -60,7 +59,7 @@ namespace zero.Web.Controllers
{
IReadOnlyCollection<PageType> pageTypes = Options.Pages.GetAllItems();
using IAsyncDocumentSession session = Raven.OpenAsyncSession();
using IAsyncDocumentSession session = Store.OpenAsyncSession();
Dictionary<string, IPage> pages = await session.LoadAsync<IPage>(ids);
Dictionary<string, IRoute> routes = await session.LoadAsync<IRoute>(pages.Where(x => x.Value != null).Select(x => "routes." + x.Value.Hash));
+7 -7
View File
@@ -17,6 +17,7 @@ using System.Threading.Tasks;
using zero.Core;
using zero.Core.Api;
using zero.Core.Assemblies;
using zero.Core.Database;
using zero.Core.Entities;
using zero.Core.Extensions;
using zero.Core.Handlers;
@@ -139,14 +140,13 @@ namespace zero.Web
void ConfigureDatabase()
{
// add raven
Services.AddSingleton(context =>
Services.AddSingleton<IZeroStore, ZeroStore>(context =>
{
IZeroOptions options = context.GetService<IZeroOptions>();
DocumentStore store = new DocumentStore()
IDocumentStore store = new ZeroStore()
{
Urls = new string[1] { options.Raven.Url },
//Database = options.Raven.Database // we do not specify a default database so every session + operation is forced to specify it
Urls = new string[1] { options.Raven.Url }
};
IDocumentStore raven = store.Setup(options).Initialize();
@@ -157,10 +157,10 @@ namespace zero.Web
// TODO maybe we shouldn't use all auto-registered assemblies but specify them directly via options?
foreach (Assembly assembly in assemblies)
{
IndexCreation.CreateIndexes(assembly, store);
IndexCreation.CreateIndexes(assembly, store, database: "laola.hofbauer");
}
return raven;
return (ZeroStore)raven;
});
}