refactor: Pass composite stream factory back to recursive factories as service
This commit is contained in:
1 parent
979051f147
commit
4ef2dbe4d7
1 file changed
+15
-4
@@ -3,10 +3,14 @@ namespace Bts.DataStreamCore;
|
||||
|
||||
using BCG;
|
||||
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
class CompositeDataStreamFactory : IDataStreamFactory {
|
||||
class CompositeDataStreamFactory : IDataStreamFactory, IHostedService {
|
||||
readonly List<IDataStreamFactory> streamFactories;
|
||||
|
||||
public CompositeDataStreamFactory(IEnumerable<IDataStreamFactory> streamFactories)
|
||||
@@ -14,9 +18,6 @@ class CompositeDataStreamFactory : IDataStreamFactory {
|
||||
|
||||
internal CompositeDataStreamFactory(List<IDataStreamFactory> streamFactories) {
|
||||
this.streamFactories = streamFactories;
|
||||
foreach (var rsf in this.streamFactories.OfType<IRecursiveDataStreamFactory>()) {
|
||||
rsf.OnCompositeFactory(this);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IDataStreamMetadata> GetSupportedStreams() =>
|
||||
@@ -27,4 +28,14 @@ class CompositeDataStreamFactory : IDataStreamFactory {
|
||||
.Select(f => f.Create(streamId, args))
|
||||
.ExceptNull()
|
||||
.FirstOrDefault();
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken) {
|
||||
foreach (var rsf in streamFactories.OfType<IRecursiveDataStreamFactory>()) {
|
||||
rsf.OnCompositeFactory(this);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) =>
|
||||
Task.CompletedTask;
|
||||
}
|
||||
Reference in new issue
Block a user