Passing initParam from ASP.NET ?

Jan 8, 2009 at 6:24 PM
Hello, i am trying to pass parameters to an SL app embedded in a Asp.Net page, which is typically done this way

 private void Application_Startup(object sender, StartupEventArgs e)
        {
            // Get the schedule id
            Bootstrapper bootstrapper = new Bootstrapper();
            bootstrapper.InitParams = e.InitParams;
            bootstrapper.Run();
        }

however i would like to pass this parameters to a specific module, loaded by the bootstrapper from a module catalog.

How can i initialize the module a parameter ?

Thank you,
Francisco
Jan 8, 2009 at 7:24 PM
Edited Jan 8, 2009 at 7:28 PM
You can use the container within the Bootstrapper as follows:

Bootstrapper

public class Bootstrapper : UnityBootstrapper

{

    public IDictionary<string,string> InitParams { get; set; }

 

    /// <summary>

    /// Creates the shell.

    /// </summary>

    /// <returns></returns>

    protected override DependencyObject CreateShell()

    {

        Container
          .RegisterInstance<IDictionary<string,string>> 
              ("InitParams", InitParams);

        Shell shell = Container.Resolve<Shell>();

 

#if SILVERLIGHT

        Application.Current.RootVisual = shell;

#else

        shell.Show();

#endif

        return shell;

    }
}


MODULE

public class EmployeeModule : IModule

{

    private readonly IUnityContainer container;

    private readonly IRegionManager regionManager;

 

    private IDictionary<string, string> initParams;

 

    /// <summary>

    /// Initializes a new instance of the class.

    /// </summary>

    /// <param name="container">The container.</param>

    /// <param name="regionManager">The region manager.</param>

    public EmployeeModule(

        IUnityContainer container,

        IRegionManager regionManager)

    {

        this.container = container;

        this.regionManager = regionManager;

 

        this.initParams =

            container.Resolve<IDictionary<string, string>>
                              ("InitParams");

    }

Jan 9, 2009 at 12:19 PM
Thanks for the prompt answer Bill,

if i understood it, this is the procedure to give global access to any object, right ? Registering it the container.

Container.RegisterInstance<IDictionary<string,string>> ("InitParams", InitParams);

this.initParams = container.Resolve<IDictionary<string, string>>("InitParams");

Francisco
Jan 9, 2009 at 7:41 PM
Correct, any registered instances will be available to resolved classes.
Sep 16, 2009 at 10:58 PM

I can't register instance like below

Container
          .RegisterInstance<IDictionary<string,string>> 
              ("InitParams", InitParams);

 

because Container seems to be read only property.