C# 在代码中定义NServiceBus实例映射

C# 在代码中定义NServiceBus实例映射,c#,nservicebus,C#,Nservicebus,我正在编写一个asp.net核心应用程序,希望向NServiceBus端点发送一条消息 由于我们有不同的环境,我需要为每个环境配置一个端点地址。我在app settings.Env.json中这样做 我喜欢对实例映射执行同样的操作。我知道的唯一方法是为每个环境使用不同的instance mapping.xml文件,或者将其添加到app.config中,而我没有。有没有办法在代码中设置实例机器?我不想有不同的XML文件 我使用NServiceBus 6.3.4我在端点配置中添加了一个功能: end

我正在编写一个asp.net核心应用程序,希望向NServiceBus端点发送一条消息

由于我们有不同的环境,我需要为每个环境配置一个端点地址。我在app settings.Env.json中这样做

我喜欢对实例映射执行同样的操作。我知道的唯一方法是为每个环境使用不同的
instance mapping.xml
文件,或者将其添加到app.config中,而我没有。有没有办法在代码中设置实例机器?我不想有不同的XML文件


我使用NServiceBus 6.3.4

我在端点配置中添加了一个功能:

endpointConfiguration.EnableFeature<MyFeature>();

public class MyFeature : Feature
{
    protected override void Setup(FeatureConfigurationContext context)
    {
        var endpointInstances = context.Settings.Get<EndpointInstances>();
        endpointInstances.AddOrReplaceInstances("InstanceMapping",
            new List<EndpointInstance>
            {
                new EndpointInstance("MyEndpoint").AtMachine("VM-1")
            });
    }
}
endpointConfiguration.enableffeature();
公共类MyFeature:Feature
{
受保护的覆盖无效设置(功能配置上下文)
{
var endpointInstances=context.Settings.Get();
endpointInstances.AddOrReplaceInstances(“InstanceMapping”,
新名单
{
新的EndpointInstance(“MyEndpoint”).AtMachine(“VM-1”)
});
}
}
检查文档和