Closed Bezarius closed 3 months ago
Found temporal solution:
public class TestObservable<T> : Observable<T>, IDisposable
{
private Subject<T> _subject = new Subject<T>();
protected override IDisposable SubscribeCore(Observer<T> observer)
{
return ObservableSubscribeExtensions.Subscribe(_subject, observer.OnNext);
}
public void Dispose()
{
_subject.Dispose();
}
}
Observable is a base class for creating Observables, so it is inappropriate to delegate it in SubscribeCore. I admit that the lack of an interface is inconvenient, but I would like you to work around this by adding AsObservable, etc.
if we change TestObservable like this everyting will be fine
Explanation:
In my opinion, the code in test is quite legal. It seems to me that this case needs to be studied and a recommendation on how to work around this problem should be added to the documentation. At the moment, I have no idea how to solve the issue correctly. Using Subject as a base class is definitely not correct. There is a feeling that support for the IObservable\IObserver interfaces is still necessary.
I can't help but draw attention to the fact that there may potentially be cases where a developer may need a different base class, not Observable. In this case, dev will have to create a separate property for the subscription, which, in my opinion, will worsen the readability of the code.