Files
spark/src/DataStreamSuite/DataStreamCore/DynamicLoading/CompositeDataStreamFactory.cs
T
John Colvin ada7d4bed1 refactor: Load IDataStreamFactory(s) with dependency injection
So we can create ViewStreams that depend on other services, config, etc.
Previously, the PrimitiveManager relied purely on static construction of
types through reflection.
2025-11-14 14:52:07 -05:00

28 lines
916 B
C#

#nullable enable
namespace Bts.DataStreamCore;
using BCG;
using System.Collections.Generic;
using System.Linq;
public class CompositeDataStreamFactory : IDataStreamFactory {
readonly List<IDataStreamFactory> streamFactories;
public CompositeDataStreamFactory(IEnumerable<IDataStreamFactory> streamFactories) {
this.streamFactories = streamFactories.ToList();
foreach (var rsf in this.streamFactories.OfType<IRecursiveDataStreamFactory>()) {
rsf.OnCompositeFactory(this);
}
}
public IEnumerable<IDataStreamMetadata> GetSupportedStreams() =>
streamFactories.SelectMany(f => f.GetSupportedStreams());
public ViewStream? Create(string streamId, IEnumerable<(string? Name, int? Index, object? Value)> args) =>
streamFactories.Where(f => f.CanCreate(streamId))
.Select(f => f.Create(streamId, args))
.ExceptNull()
.FirstOrDefault();
}