views:

53

answers:

1

I want to use the iobservable pattern to expose a stream of events. The problem is that I'm using unity to create both the observer and the event generator. I would rather not have to new up both of these at application start just so I can start listening for events. Does any one have any suggestions about this?

+1  A: 

After reading your reply to my comment (sorry about the delay, see my comment) I can think of two ways of solving it.

Firstly, have the subscriber subscriber to an IObservable that wraps (ie. subscribes to) the yet-to-be-created IObservable source. This way, the subscriber can subscribe immediately, but the values won't start coming through until the source has been created.

The other choice is to create an IObservable flavoured version of the EventAggregator that ships with Prism (2.2, I haven't checked out 4). The EventAggregator acts as a broadcast event system, whereby any piece of code can ask for an Event which can be either subscribed to or published to. In your case, the event would implement ISubject (that is, both IObservable and IObserver).

Richard Szalay