如何解决如何列出 ASP.NET Core Web 服务的端点? 当前实现
背景
我需要找到一种方法让我的应用程序通过 UDP 广播它的绑定地址,而不使用 IServerAddressesFeature
。
尽管 BackgroundService
实现在路由发生之前启动,但我找到了一种方法来运行我的广播服务,但出于某种原因,每当我部署我的应用程序时,IServerAddressesFeature
将不再为我提供地址,而它在调试时报告正确的地址。
问题
是否有一些配置选项我可以用来从那里解析 url 并跳过诊断该功能在调试时有效但在部署时无效的原因?
关于可能的答案
如果您有预感为什么它在部署时不起作用,请随时告诉我 - 此时我已放弃通过 IServerAddressesFeature
执行此操作,并且配置解析方法对我来说已经足够了
当前实现
启动.配置服务
... lots of configuration
applicationStateTransmitter.NotifyConfigurationDone();
applicationStateTransmitter.NotifyBindingAddressesAvailable(app.ServerFeatures.Get<IServerAddressesFeature>().Addresses);
... end of ConfigureServices
我的服务类曾经绕过 BackgroundWorker
的限制:
public class ApplicationStateTransmitter
{
private readonly taskcompletionsource _configurationDone;
private readonly taskcompletionsource<ICollection<string>> _bindingAddressesAvailable;
public ApplicationStateTransmitter()
{
_configurationDone = new taskcompletionsource(null);
_bindingAddressesAvailable = new taskcompletionsource<ICollection<string>>(null);
}
public Task ConfigurationDone => _configurationDone.Task;
public void NotifyConfigurationDone() => _configurationDone.SetResult();
public Task<ICollection<string>> BindingAddressesAvailable => _bindingAddressesAvailable.Task;
public void NotifyBindingAddressesAvailable(ICollection<string> values) => _bindingAddressesAvailable.SetResult(values);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。