如何列出 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 (将#修改为@)