每次调用时Configuration.GetSection,Value返回对象的属性始终为null.
我的Startup构造函数
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables();
this.Configuration = builder.Build();
}
Run Code Online (Sandbox Code Playgroud)
我的ConfigureServices方法
public void ConfigureServices(IServiceCollection services)
{
services.Configure<SqliteSettings>(opts => Configuration.GetSection("SqliteSettings").Bind(opts));
services.AddOptions();
services.AddMvc();
}
Run Code Online (Sandbox Code Playgroud)
我的 appsettings.json
{
"SqliteSettings": {
"DataSource": "C:\\db.sqlite",
"NewDatabase": true,
"Version": 3
}
}
Run Code Online (Sandbox Code Playgroud)
我用来定义SqliteSettings的类
public class SqliteSettings
{
public string DataSource { get; set; }
public bool? NewDatabase { get; set; }
public int? Version { get; set; …Run Code Online (Sandbox Code Playgroud) 我尝试按照Boost 在其文档中提供的教程安装 boost,并查看了此处的其他一些问题,以尝试确定为什么我无法在自定义位置安装 Boost。也许我误解了,但该--prefix选项应该指定 Boost 标头和库的位置,然后bootstrapper.sh创建一个在运行.jam时使用的文件。b2bjam
当我发出以下命令时
./bootstrap.sh --prefix="$HOME/dev/emulator/src/boost" --includedir=headers --libdir=dist --with-libraries=date_time
Run Code Online (Sandbox Code Playgroud)
我看到正确的行已添加到生成的project-config.jam文件中
option.set prefix : /home/liam/dev/emulator/src/boost ;
option.set exec-prefix : /home/liam/dev/emulator/src/boost ;
option.set libdir : dist ;
option.set includedir : headers ;
Run Code Online (Sandbox Code Playgroud)
但是,当我./b2按照文档的指示运行时,它将 Boost 库安装到源文件夹中;IE
The following directory should be added to compiler include paths:
/home/liam/Downloads/brave/boost_1_66_0
The following directory should be added to linker library paths:
/home/liam/Downloads/brave/boost_1_66_0/stage/lib
Run Code Online (Sandbox Code Playgroud)
并且运行./b2 install也不给我任何文件输出到预期的目录。
我试图用Hyper发送一个请求,然后通过Serde通过JSON反序列化它,但是我似乎无法束手无策,我收到了类型不匹配错误的说明expected (), found struct [put some odd struct here]。我也无法绕过每次更改都会吐出的令人难以置信的冗长而令人困惑的错误消息。这是我的代码:
extern crate futures;
extern crate hyper;
extern crate serde;
extern crate serde_json;
use futures::{
Future,
Stream,
future
};
use hyper::{
Body,
Client,
Response,
StatusCode,
Uri,
client::HttpConnector,
};
use serde::{ Deserialize };
use std::error::{ Error };
enum JsonError
{
RequestError(hyper::Error),
ResponseError(StatusCode),
DeserializeError(serde_json::Error),
}
fn get_json
<'t, T, F>
(client: &Client<HttpConnector>, uri: Uri)
-> impl Future<Item = T, Error = JsonError>
where
T : Deserialize<'t> …Run Code Online (Sandbox Code Playgroud)