Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8924345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:23:11+00:00 2026-06-15T07:23:11+00:00

In this answer to a question about Subject<T> Enigmativity mentioned: as an aside, you

  • 0

In this answer to a question about Subject<T> Enigmativity mentioned:

as an aside, you should try to avoid using subjects at all. The
general rule is that if you’re using a subject then you’re doing
something wrong.

I often use subjects as backing fields for IObservable properties, which would have probably been .NET events in the days before Rx. e.g. instead of something like

public class Thing
{
    public event EventHandler SomethingHappened;

    private void DoSomething()
    {
        Blah();
        SomethingHappened(this, EventArgs.Empty);
    }
}

I might do

public class Thing
{
    private readonly Subject<Unit> somethingHappened = new Subject<Unit>();
    public IObservable<Unit> SomethingHappened
    {
        get { return somethingHappened; }
    }

    private void DoSomething()
    {
        Blah();
        somethingHappened.OnNext(Unit.Default);
    }
}

So, if I want to avoid using Subject what would be the correct way of doing this kind of thing? Or I should I stick to using .NET events in my interfaces, even when they’ll be consumed by Rx code (so probably FromEventPattern)?

Also, a bit more details on why using Subject like this is a bad idea would be helpful.

Update: To make this question a bit more concrete, I’m talking about using Subject<T> as a way to get from non-Rx code (maybe you’re working with some other legacy code) into the Rx world. So, something like:

class MyVolumeCallback : LegacyApiForSomeHardware
{
    private readonly Subject<int> volumeChanged = new Subject<int>();

    public IObservable<int> VolumeChanged
    {
        get
        {
            return volumeChanged.AsObservable();
        }
    }

    protected override void UserChangedVolume(int newVolume)
    {
        volumeChanged.OnNext(newVolume);
    }
}

Where, instead of using events, the LegacyApiForSomeHardware type makes you override virtual methods as a way of getting “this just happened” notifications.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:23:12+00:00Added an answer on June 15, 2026 at 7:23 am

    In an answer on the Rx forum, Dave Sexton (of Rxx), said as part an answer to something:

    Subjects are the stateful components of Rx. They are useful for when
    you need to create an event-like observable as a field or a local
    variable.

    Which is exactly what’s happening with this question, he also wrote an in-depth follow up blog post on To Use Subject Or Not To Use Subject? which concludes with:

    When should I use a subject?

    When all of the following are true:

    • you don’t have an observable or anything that can be converted into one.
    • you require a hot observable.
    • the scope of your observable is a type.
    • you don’t need to define a similar event and no similar event already exists.

    Why should I use a subject in that case?

    Because you’ve got no choice!

    So, answering the inner question of “details on why using Subject like this is a bad idea” – it’s not a bad idea, this is one of the few places were using a Subject is the correct way to do things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I submitted an answer to this SO question about redirecting your site ,
I've found an answer to a previous question about javascript short hand for this
I have spent about half a day searching for an answer to this question
Somewhat related to this question , but in the absence of any answer about
In this answer to a question about the definitions of NP, NP-hard, and NP-complete,
I'm hoping someone can answer this question about an SQL query I'm tyring to
I just learned about the Template Method pattern in this answer to a question
In the accepted answer to this SO question there is an explanation about structural
I've checked other threads about this subject, but nothing really answers my exact question.
There are nice SO question and answers about this issue, but these options didn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.