I read the following code for Windsor installer.
public class MessagingInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
var subject = new Subject<IMessage>();
var ss = Subject.Synchronize(subject);
container.Rgister(
Component.For<IObserver<IMessage>>().Instance(ss.AsObserver()),
Component.For<IObservable<IMessage>>().Instance(ss.AsObservable()),
And classes inject IObserver<IMessage> publisher, which will call publisher.OnNext(...) to push values, and other classes inject <IObservable<IMessage> source, which subscribe source.
The question is ss is a local variable in the method Install(...). How does ss be used by other classes?
It's not possible to use it from other classes. It's only in scope for the lifetime of the
Install()method.The instance returned from the
ss.AsObservable()method call is being registered with the container, and is accessible to other classes via DI. I'm assuming that the instance returned by theAsObservable()method is not the same instance asss?If you want the instance
ssrefers to, to be accessible to other classes via DI, you would have to register that instance instead: