Quantcast
Channel: patterns & practices: Prism
Viewing all articles
Browse latest Browse all 1878

New Post: Gathering User Information before Bootstrapper Runs

$
0
0
Federico,

Thank you for your help. I have a couple of issues that are stopping me from getting to my ultimate goal.
  1. On all of the Logger.Log lines, I am getting a Resource error. My system is not recognizing the Resources.LoggerCreatedSuccessfully
    Is this a file that I should be creating with constants.
  2. My bigger issue involves the CreateModuleCatalog. I might not have explained myself correctly in the initial issue.
    Here is what I want my CreateModuleCatalog to do.
    protected override IModuleCatalog CreateModuleCatalog()
    {
        ModuleCatalog modules = new ModuleCatalog();
        modules.AddModule(typeof(NSAMedia.VendorAutomation.Modules.VendorDetail.VendorDetailModule));
        if (userPrincipal.UserID != 3417)
        {
            modules.AddModule(typeof(NSAMedia.VendorAutomation.Modules.VendorSelection.VendorSelectionModule));
        }
        modules.AddModule(typeof(NSAMedia.VendorAutomation.Modules.ProductSelection.ProductSelectionModule));
        modules.AddModule(typeof(NSAMedia.VendorAutomation.Modules.ProductDetails.ProductDetailsModule));
        return modules;
    }
    
I want to wait for my UserPrincipal to complete (which the system is allowing) because I want to add some modules based on who is logging in. In the code you supplied, I am still calling the CreateModuleCatalog, ConfigureModuleCatalog, CreateContainer, ConfigureContainer, ... before the web service is done. In this case my userPrincipal.UserID = 0 and all Modules are loaded, even though after the service is done, userPrinicipal.userID = 3417 and the VendorSelection module should not be loaded. I was hoping to do something like the following but cannot because the ServiceLocator is null again as in my previous entry.
    public override void Run(bool runWithDefaultConfiguration)
    {
        //this.useDefaultConfiguration = runWithDefaultConfiguration;
        ServiceLocator.Current.GetInstance<IEventAggregator>().GetEvent<UserInitialized>().Subscribe(this.UserDone);
    }

    public void UserDone(UserPrincipal user)
    {
        ServiceLocator.Current.GetInstance<IEventAggregator>().GetEvent<UserInitialized>().Unsubscribe(this.UserDone);

        this.Logger = this.CreateLogger();
        if (this.Logger == null)
        {
            //throw new InvalidOperationException(Resources.NullLoggerFacadeException);
        }

        //this.Logger.Log(Resources.LoggerCreatedSuccessfully, Category.Debug, Priority.Low);

        //this.Logger.Log(Resources.CreatingModuleCatalog, Category.Debug, Priority.Low);
        this.ModuleCatalog = this.CreateModuleCatalog();
        if (this.ModuleCatalog == null)
        {
            //throw new InvalidOperationException(Resources.NullModuleCatalogException);
        }

        //this.Logger.Log(Resources.ConfiguringModuleCatalog, Category.Debug, Priority.Low);
        this.ConfigureModuleCatalog();

        //this.Logger.Log(Resources.CreatingUnityContainer, Category.Debug, Priority.Low);
        this.Container = this.CreateContainer();
        if (this.Container == null)
        {
            //throw new InvalidOperationException(Resources.NullUnityContainerException);
        }

        //this.Logger.Log(Resources.ConfiguringUnityContainer, Category.Debug, Priority.Low);
        this.ConfigureContainer();

        //this.Logger.Log(Resources.ConfiguringServiceLocatorSingleton, Category.Debug, Priority.Low);
        this.ConfigureServiceLocator();

        //this.Logger.Log(Resources.ConfiguringRegionAdapters, Category.Debug, Priority.Low);
        this.ConfigureRegionAdapterMappings();

        //this.Logger.Log(Resources.ConfiguringDefaultRegionBehaviors, Category.Debug, Priority.Low);
        this.ConfigureDefaultRegionBehaviors();

        //this.Logger.Log(Resources.RegisteringFrameworkExceptionTypes, Category.Debug, Priority.Low);
        this.RegisterFrameworkExceptionTypes();

        //this.Logger.Log(Resources.CreatingShell, Category.Debug, Priority.Low);
        this.Shell = this.CreateShell();
        if (this.Shell != null)
        {
            //this.Logger.Log(Resources.SettingTheRegionManager, Category.Debug, Priority.Low);
            RegionManager.SetRegionManager(this.Shell, this.Container.Resolve<IRegionManager>());

            //this.Logger.Log(Resources.UpdatingRegions, Category.Debug, Priority.Low);
            RegionManager.UpdateRegions();

            //this.Logger.Log(Resources.InitializingShell, Category.Debug, Priority.Low);
            this.InitializeShell();
        }

        if (this.Container.IsRegistered<IModuleManager>())
        {
            //this.Logger.Log(Resources.InitializingModules, Category.Debug, Priority.Low);
            this.InitializeModules();
            //this.Logger.Log(Resources.BootstrapperSequenceCompleted, Category.Debug, Priority.Low);
        }
    }

    protected override void ConfigureContainer()
    {
        Container.RegisterInstance(typeof(UserPrincipal), userPrincipal, new ContainerControlledLifetimeManager());

        base.ConfigureContainer();
    }


   protected override IModuleCatalog CreateModuleCatalog()
    {
        ModuleCatalog modules = new ModuleCatalog();
        modules.AddModule(typeof(NSAMedia.VendorAutomation.Modules.VendorDetail.VendorDetailModule));
        if (userPrincipal.UserID != 3417)
        {
            modules.AddModule(typeof(NSAMedia.VendorAutomation.Modules.VendorSelection.VendorSelectionModule));
        }
        modules.AddModule(typeof(NSAMedia.VendorAutomation.Modules.ProductSelection.ProductSelectionModule));
        modules.AddModule(typeof(NSAMedia.VendorAutomation.Modules.ProductDetails.ProductDetailsModule));
        return modules;
    }


Viewing all articles
Browse latest Browse all 1878

Trending Articles



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