-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathEndpointAddressConfiguration.cs
63 lines (51 loc) · 2.61 KB
/
EndpointAddressConfiguration.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
namespace NServiceBus
{
using System;
using Configuration.AdvancedExtensibility;
using Routing;
using Transport.SqlServer;
/// <summary>
/// Configuration extensions for endpoint catalog and schema settings
/// </summary>
public static class EndpointAddressConfiguration
{
/// <summary>
/// Specifies custom schema for given endpoint.
/// </summary>
/// <param name="settings"><see cref="RoutingSettings"/></param>
/// <param name="endpointName">Endpoint name.</param>
/// <param name="schema">Custom schema value.</param>
public static void UseSchemaForEndpoint(this RoutingSettings settings, string endpointName, string schema)
{
ArgumentNullException.ThrowIfNull(endpointName);
var localEndpointName = settings.GetSettings().EndpointName();
if (endpointName.Equals(localEndpointName))
{
throw new ArgumentException("Custom schema cannot be specified for the local endpoint.");
}
var schemaAndCatalogSettings = settings.GetSettings().GetOrCreate<EndpointSchemaAndCatalogSettings>();
schemaAndCatalogSettings.SpecifySchema(endpointName, schema);
settings.GetSettings().GetOrCreate<EndpointInstances>()
.AddOrReplaceInstances("SqlServer", schemaAndCatalogSettings.ToEndpointInstances());
}
/// <summary>
/// Specifies custom catalog for given endpoint.
/// </summary>
/// <param name="settings">The <see cref="RoutingSettings" /> to extend.</param>
/// <param name="endpointName">Endpoint name.</param>
/// <param name="catalog">Custom catalog value.</param>
public static void UseCatalogForEndpoint(this RoutingSettings settings, string endpointName, string catalog)
{
ArgumentNullException.ThrowIfNull(endpointName);
var localEndpointName = settings.GetSettings().EndpointName();
if (endpointName.Equals(localEndpointName))
{
throw new ArgumentException("Custom catalog cannot be specified for the local endpoint. Local endpoint's schema can be specified with DefaultSchema transport setting.");
}
var schemaAndCatalogSettings = settings.GetSettings().GetOrCreate<EndpointSchemaAndCatalogSettings>();
schemaAndCatalogSettings.SpecifyCatalog(endpointName, catalog);
settings.GetSettings().GetOrCreate<EndpointInstances>()
.AddOrReplaceInstances("SqlServer", schemaAndCatalogSettings.ToEndpointInstances());
}
}
}