在.Net Core文档中,他们指出此示例使用委托函数:
// Example #2: Options bound and configured by a delegate
services.Configure<MyOptionsWithDelegateConfig>(myOptions =>
{
myOptions.Option1 = "value1_configured_by_delegate";
myOptions.Option2 = 500;
});
我可以使用它,但是我想调用一个方法来充实Options对象,就像这样:
private void RegisterOptionsFromDatabase(OrmLiteConnectionFactory dbConnectionFactory, IServiceCollection services)
{
// Example #2: Options bound and configured by a delegate
services.Configure<PublishingAppSettings>(myOptions => { myOptions = configFromDb(dbConnectionFactory); });
}
但是,我知道Lambda函数存在问题,因为使用这些选项时我会返回NULL对象。
我做错了什么?