用来初始化DocumentStore

问题描述:

在ASP.NET核心的WebAPI RavenDB错误我有RavenDB 版本项目的WebAPI ASP.NET核心(.NET框架):用来初始化DocumentStore

  • RavendDB V3.5.3
  • ASP.NET核心V1 0.1
  • 的.NET Framework v4.6.2
  • RavenDB.Client V3.5.3

我的代码:

启动类

public void ConfigureServices(IServiceCollection services) 
    { 
     // Add framework services. 
     services.AddMvc(); 
     DocumentStoreHolder.DatabaseName = "database"; 
     DocumentStoreHolder.Url = "http://localhost:8080/"; 
     services.AddSingleton(DocumentStoreHolder.Store); 
     services.AddScoped<ISearchRepository, SearchRepository>(); 
    } 

DocumentStoreHolder

public class DocumentStoreHolder 
    { 
     private static readonly Lazy<IDocumentStore> store = new Lazy<IDocumentStore>(CreateStore); 
     public static string Url { get; set; } 
     public static string DatabaseName { get; set; } 

     public static IDocumentStore Store 
     { 
      get { return store.Value; } 
     } 

     private static IDocumentStore CreateStore() 
     { 
      var store = new DocumentStore 
      { 
       Url = Url, 
       DefaultDatabase = DatabaseName 
      }.Initialize(); 

      return store; 
     } 
    } 

public class SearchRepository : ISearchRepository 
    { 
     private readonly IDocumentStore _store; 

     public async Task<string> Add(SearchRavenDto dto) 
     { 
      using (var session = _store.OpenSession()) 
      { 
       session.Store(dto); 
       session.SaveChanges(); 
       return dto.Id; 
      } 
     } 
    } 

期间DocumentStoreHolder类DocumentStore的初始化我收到错误:

System.IO.FileNotFoundException: 'Could not load file or assembly 'NLog' or one of its dependencies. The system cannot find the file specified.'

安装NLOG v4.4.11后我收到错误:

Raven.Abstractions.Connection.ErrorResponseException: 'replication bundle not activated in database named: '

在另一应用中(控制台应用程序的.NET Framework)相同的代码工作正常。

请问您能帮我吗?

这些是在内部处理并且对系统没有影响的例外情况。 只需在VS中按F5并让它运行。