小编Hel*_*igo的帖子

使用RavenDB设置dotnet核心

我目前在为多个环境设置带有dotnet核心的RavenDB时遇到问题。

StartUp类中,我已将Raven配置为Singleton,并使用IOptions模式将Raven设置绑定到RavenSettings对象。

 public virtual void ConfigureServices(IServiceCollection services)
 {
     Services.AddMvc()

     //Add functionality to inject IOptions<T> 
     services.AddOptions();

     // App Settings
     services.Configure<RavenSettings>(Configuration.GetSection("Raven"));
     //services.Configure<RavenSettings>(settings => Configuration.GetSection("Raven").Bind(settings));

     // .NET core built in IOC
     services.AddSingleton(DocumentStoreHolder.Store);
     services.AddSingleton<IConfiguration>(Configuration);
 }
Run Code Online (Sandbox Code Playgroud)

这是我的默认应用设置。

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
      }
  },
  "Raven": {
    "Url": "x",
    "DefaultDatabase": "x"
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我尝试将设置从appsettings绑定到...的类。

public class RavenSettings
{
    public string Url { get; set; }
    public string DefaultDatabase …
Run Code Online (Sandbox Code Playgroud)

dependency-injection ravendb .net-core

4
推荐指数
1
解决办法
1405
查看次数

标签 统计

.net-core ×1

dependency-injection ×1

ravendb ×1