lambda Options
如何在.NET Core中与services.Add*
一起使用?.net核心中的配置选项
我通常做services.Configure
以下,
services.Configure<MyOptions>(
Configuration.GetSection("my-option-section-in-appsettings.json"));
或lambda变种,
services.Configure<MyOptions>(options =>
{
options.PropertyName = "some-thing"
}
但是,当涉及到下面,我迷路了,
services.AddMyService(options => options.UseMethod1(...));
我尝试遍历上面使用的代码,但我找不到我的路。我能得到最快的例子是here
我不认为这是可能的,因为配置服务是为了保存信息。我会建议实现一个简单的服务......就像在同一个链接的services文件夹中完成的一样:https://github.com/aspnet/Identity/tree/dev/samples/IdentitySample.Mvc/Services – Kris
我不喜欢不明白为什么你说这是不可能的,虽然我提供的链接清楚地包含了这个'options.UseSqlServer(Configuration.GetConnectionString(“DefaultConnection”))' –
您正在询问在配置中调用一个方法,仔细看看你的链接。在你的例子中,在UseSqlServer的Lambda中有一个方法调用,它不是配置... – Kris