Event Subscription does not connect with the event published












0















I have two ViewModels. In one of them I publish this event



_eventAggregator.GetEvent<AddUbicacionEvent>().Publish(sensorUbicado.Sensor.CodigoInterno);


And the in the other one I have this in the constructor



 _eventAggregator.GetEvent<AddUbicacionEvent>().Subscribe(OnReceiveUbicacion);


And this method



 private void OnReceiveUbicacion(string obj)
{
MessageBox.Show("Event Captured");
}


But the Code never stops in this method



I'm Using AutoFac to inject the Event Aggergator in the constructor of the view models



 public IContainer Bootstrap()
{
var builder = new ContainerBuilder();

builder.RegisterType<EventAggregator>().As<IEventAggregator>().SingleInstance();


Then I have this



 public PrincipalViewModel(IEventAggregator eventAggregator, IUbicacionRepository ubicacionRepository, ComponenteEscucha componenteEscucha)
{

_eventAggregator = eventAggregator;


And this



 public GestionUbicacionesViewModel(IEventAggregator eventAggregator, ):base(eventAggregator)
{
_eventAggregator = eventAggregator;


Any idea please?



Regards










share|improve this question

























  • is _eventAggregator the same instance in both view models?

    – ASh
    Nov 23 '18 at 18:32











  • This is one of the downsides of eventaggregator. Because it's an instance you're pub/subbing you need to pass it round somehow. Either dependency injection or resources are the usual choices unless one vm is the child of the other and you can just pass it into the constructor.

    – Andy
    Nov 23 '18 at 19:20













  • if you use ViewModelLocator, the event aggregator is the same usually, no need to worry there. but when do your view models get created? the subscriber has to be alive (and have subscribed) when the event is published.

    – Haukinger
    Nov 24 '18 at 17:18











  • I'm injecting IEventAggregator in the constructor of both VMs by AutoFac

    – kintela
    Nov 26 '18 at 10:19













  • yeah, sure, but when do you navigate to each of the view models?

    – Haukinger
    Nov 27 '18 at 10:11
















0















I have two ViewModels. In one of them I publish this event



_eventAggregator.GetEvent<AddUbicacionEvent>().Publish(sensorUbicado.Sensor.CodigoInterno);


And the in the other one I have this in the constructor



 _eventAggregator.GetEvent<AddUbicacionEvent>().Subscribe(OnReceiveUbicacion);


And this method



 private void OnReceiveUbicacion(string obj)
{
MessageBox.Show("Event Captured");
}


But the Code never stops in this method



I'm Using AutoFac to inject the Event Aggergator in the constructor of the view models



 public IContainer Bootstrap()
{
var builder = new ContainerBuilder();

builder.RegisterType<EventAggregator>().As<IEventAggregator>().SingleInstance();


Then I have this



 public PrincipalViewModel(IEventAggregator eventAggregator, IUbicacionRepository ubicacionRepository, ComponenteEscucha componenteEscucha)
{

_eventAggregator = eventAggregator;


And this



 public GestionUbicacionesViewModel(IEventAggregator eventAggregator, ):base(eventAggregator)
{
_eventAggregator = eventAggregator;


Any idea please?



Regards










share|improve this question

























  • is _eventAggregator the same instance in both view models?

    – ASh
    Nov 23 '18 at 18:32











  • This is one of the downsides of eventaggregator. Because it's an instance you're pub/subbing you need to pass it round somehow. Either dependency injection or resources are the usual choices unless one vm is the child of the other and you can just pass it into the constructor.

    – Andy
    Nov 23 '18 at 19:20













  • if you use ViewModelLocator, the event aggregator is the same usually, no need to worry there. but when do your view models get created? the subscriber has to be alive (and have subscribed) when the event is published.

    – Haukinger
    Nov 24 '18 at 17:18











  • I'm injecting IEventAggregator in the constructor of both VMs by AutoFac

    – kintela
    Nov 26 '18 at 10:19













  • yeah, sure, but when do you navigate to each of the view models?

    – Haukinger
    Nov 27 '18 at 10:11














0












0








0








I have two ViewModels. In one of them I publish this event



_eventAggregator.GetEvent<AddUbicacionEvent>().Publish(sensorUbicado.Sensor.CodigoInterno);


And the in the other one I have this in the constructor



 _eventAggregator.GetEvent<AddUbicacionEvent>().Subscribe(OnReceiveUbicacion);


And this method



 private void OnReceiveUbicacion(string obj)
{
MessageBox.Show("Event Captured");
}


But the Code never stops in this method



I'm Using AutoFac to inject the Event Aggergator in the constructor of the view models



 public IContainer Bootstrap()
{
var builder = new ContainerBuilder();

builder.RegisterType<EventAggregator>().As<IEventAggregator>().SingleInstance();


Then I have this



 public PrincipalViewModel(IEventAggregator eventAggregator, IUbicacionRepository ubicacionRepository, ComponenteEscucha componenteEscucha)
{

_eventAggregator = eventAggregator;


And this



 public GestionUbicacionesViewModel(IEventAggregator eventAggregator, ):base(eventAggregator)
{
_eventAggregator = eventAggregator;


Any idea please?



Regards










share|improve this question
















I have two ViewModels. In one of them I publish this event



_eventAggregator.GetEvent<AddUbicacionEvent>().Publish(sensorUbicado.Sensor.CodigoInterno);


And the in the other one I have this in the constructor



 _eventAggregator.GetEvent<AddUbicacionEvent>().Subscribe(OnReceiveUbicacion);


And this method



 private void OnReceiveUbicacion(string obj)
{
MessageBox.Show("Event Captured");
}


But the Code never stops in this method



I'm Using AutoFac to inject the Event Aggergator in the constructor of the view models



 public IContainer Bootstrap()
{
var builder = new ContainerBuilder();

builder.RegisterType<EventAggregator>().As<IEventAggregator>().SingleInstance();


Then I have this



 public PrincipalViewModel(IEventAggregator eventAggregator, IUbicacionRepository ubicacionRepository, ComponenteEscucha componenteEscucha)
{

_eventAggregator = eventAggregator;


And this



 public GestionUbicacionesViewModel(IEventAggregator eventAggregator, ):base(eventAggregator)
{
_eventAggregator = eventAggregator;


Any idea please?



Regards







wpf prism eventaggregator






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 10:10







kintela

















asked Nov 23 '18 at 18:16









kintelakintela

1611114




1611114













  • is _eventAggregator the same instance in both view models?

    – ASh
    Nov 23 '18 at 18:32











  • This is one of the downsides of eventaggregator. Because it's an instance you're pub/subbing you need to pass it round somehow. Either dependency injection or resources are the usual choices unless one vm is the child of the other and you can just pass it into the constructor.

    – Andy
    Nov 23 '18 at 19:20













  • if you use ViewModelLocator, the event aggregator is the same usually, no need to worry there. but when do your view models get created? the subscriber has to be alive (and have subscribed) when the event is published.

    – Haukinger
    Nov 24 '18 at 17:18











  • I'm injecting IEventAggregator in the constructor of both VMs by AutoFac

    – kintela
    Nov 26 '18 at 10:19













  • yeah, sure, but when do you navigate to each of the view models?

    – Haukinger
    Nov 27 '18 at 10:11



















  • is _eventAggregator the same instance in both view models?

    – ASh
    Nov 23 '18 at 18:32











  • This is one of the downsides of eventaggregator. Because it's an instance you're pub/subbing you need to pass it round somehow. Either dependency injection or resources are the usual choices unless one vm is the child of the other and you can just pass it into the constructor.

    – Andy
    Nov 23 '18 at 19:20













  • if you use ViewModelLocator, the event aggregator is the same usually, no need to worry there. but when do your view models get created? the subscriber has to be alive (and have subscribed) when the event is published.

    – Haukinger
    Nov 24 '18 at 17:18











  • I'm injecting IEventAggregator in the constructor of both VMs by AutoFac

    – kintela
    Nov 26 '18 at 10:19













  • yeah, sure, but when do you navigate to each of the view models?

    – Haukinger
    Nov 27 '18 at 10:11

















is _eventAggregator the same instance in both view models?

– ASh
Nov 23 '18 at 18:32





is _eventAggregator the same instance in both view models?

– ASh
Nov 23 '18 at 18:32













This is one of the downsides of eventaggregator. Because it's an instance you're pub/subbing you need to pass it round somehow. Either dependency injection or resources are the usual choices unless one vm is the child of the other and you can just pass it into the constructor.

– Andy
Nov 23 '18 at 19:20







This is one of the downsides of eventaggregator. Because it's an instance you're pub/subbing you need to pass it round somehow. Either dependency injection or resources are the usual choices unless one vm is the child of the other and you can just pass it into the constructor.

– Andy
Nov 23 '18 at 19:20















if you use ViewModelLocator, the event aggregator is the same usually, no need to worry there. but when do your view models get created? the subscriber has to be alive (and have subscribed) when the event is published.

– Haukinger
Nov 24 '18 at 17:18





if you use ViewModelLocator, the event aggregator is the same usually, no need to worry there. but when do your view models get created? the subscriber has to be alive (and have subscribed) when the event is published.

– Haukinger
Nov 24 '18 at 17:18













I'm injecting IEventAggregator in the constructor of both VMs by AutoFac

– kintela
Nov 26 '18 at 10:19







I'm injecting IEventAggregator in the constructor of both VMs by AutoFac

– kintela
Nov 26 '18 at 10:19















yeah, sure, but when do you navigate to each of the view models?

– Haukinger
Nov 27 '18 at 10:11





yeah, sure, but when do you navigate to each of the view models?

– Haukinger
Nov 27 '18 at 10:11












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451364%2fevent-subscription-does-not-connect-with-the-event-published%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451364%2fevent-subscription-does-not-connect-with-the-event-published%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Ottavio Pratesi

Tricia Helfer

15 giugno