This allows us to create loosely coupled services with automatic dependency resolution
41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
namespace Bts.PubSub.Routing;
|
|
|
|
using BCG;
|
|
|
|
using bts;
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
public class PubSubRoutingConfig : ICloneable<PubSubRoutingConfig> {
|
|
public List<PubSubRoute>? PublisherRoutes { get; set; }
|
|
|
|
public List<PubSubRoute>? SubscriberRoutes { get; set; }
|
|
|
|
public void MergeWith(PubSubRoutingConfig other) {
|
|
PublisherRoutes = MergeRoutes(PublisherRoutes, other.PublisherRoutes);
|
|
SubscriberRoutes = MergeRoutes(SubscriberRoutes, other.SubscriberRoutes);
|
|
|
|
List<PubSubRoute>? MergeRoutes(List<PubSubRoute>? routes, List<PubSubRoute>? otherRoutes) {
|
|
if (otherRoutes is null) {
|
|
return routes;
|
|
}
|
|
if (routes is null) {
|
|
return otherRoutes;
|
|
}
|
|
foreach (var route in otherRoutes) {
|
|
if (!routes.Any(r => r.TagRegExp == route.TagRegExp || r.Name == route.Name)) {
|
|
routes.Add(route);
|
|
}
|
|
}
|
|
return routes;
|
|
}
|
|
}
|
|
|
|
public PubSubRoutingConfig Clone() =>
|
|
new() {
|
|
PublisherRoutes = PublisherRoutes?.Select(r => r.Clone()).ToList(),
|
|
SubscriberRoutes = SubscriberRoutes?.Select(r => r.Clone()).ToList(),
|
|
};
|
|
}
|