Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

EventAggregator Null Value

$
0
0

Hello,

I am developing an application where i do not have menu buttons within shell view and with its functionallity loads other views in predefined regions.

However,

I do publish an event from my mainproject, of my solutions, viewmodel like:

public ICommand SokKundCommand
        {
            get {
                    if (sokKundCommand == null)
                    {
                        sokKundCommand = new DelegateCommand(() => myEventAggregator.GetEvent<ActivateEvent>()
                            .Publish(new ActivateOption(ViewType.SokKundView, WellKnownRegionNames.Region1)),() => true);
                    }
                    return sokKundCommand; 
                }                                                                                            
        }

and when pressing button i got error message that "myEventAggregator" is Null and program stops.

Pleas see my MainProject ViewModel

 class MainProjectViewModel:NotificationObject
    {
        private IEventAggregator myEventAggregator;
        private DelegateCommand sokKundCommand;
        private DelegateCommand stangApplikationCommand;

        public MainProjectViewModel()
        {
            
        }
        
        public MainProjectSystemViewModel(IEventAggregator ea)
        {
            this.myEventAggregator = ea;
        }

I understand that I must inject IEventAggregator within my ViewModel in order to publish/subscribe events between modules.

Please help me to

1. Inject in right way to my ViewModel so I can consume eventAggreator

2. Do it in right way in my bootstraper. Please see my bootstraper. Am i doind something wrong anywhere?

 public class Bootstrapper:UnityBootstrapper
    {
        protected override ILoggerFacade CreateLogger()
        {
            return base.CreateLogger(); 
        }

        protected override DependencyObject CreateShell()
        {
            return new Shell();
        }

        protected override void InitializeShell()
        {
            base.InitializeShell();
            App.Current.MainWindow = (Window)this.Shell;
            App.Current.MainWindow.Show();
        }
       
        protected override IModuleCatalog CreateModuleCatalog()
        {
            var moduleCatalog = new ModuleCatalog();
            Type kundModule = typeof(KundModul);
            moduleCatalog.AddModule(new ModuleInfo() { ModuleName = kundModule.Name, ModuleType = kundModule.AssemblyQualifiedName });
            return moduleCatalog;
        }

        protected override void ConfigureContainer()
        {   
            base.ConfigureContainer();
            RegisterTypeIfMissing(typeof(IServiceLocator), typeof(UnityServiceLocatorAdapter), true);
            RegisterTypeIfMissing(typeof(IEventAggregator), typeof(EventAggregator), true);
        }

        protected override void ConfigureModuleCatalog()
        {
            base.ConfigureModuleCatalog();   
        }

        protected override void InitializeModules()
        {
            base.InitializeModules();
        }
        
    }
Thanks!


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>