0

in my application i had done log-in in WPF using prism after log-in i have to store some value (like user_id,username etc) that can be accessible in to may module so how can i resolve that problem using prism with MEF

   private void Login()
        {
            try
            {
                authentication.Login(LoginModel.UserName, LoginModel.Password);             
                // what i want to do here
                (new InventoryBootstrapper()).Run();                   
                App.Current.Windows[0].Close();
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;   
            }            
        }
leppie
  • 115,091
  • 17
  • 196
  • 297
Sanjay Patel
  • 955
  • 1
  • 8
  • 22

2 Answers2

1

There are two ways that I know of.

First you can have a 'Common' service. Use this as a service like any other module you register, it gets instantiated when the app opens, then you can call this service and use the values within as you need to.

Secondly, you could also have a 'Common' project that every module references, from your core module to all modules.

TrialAndError
  • 1,784
  • 3
  • 20
  • 41
  • but i think it's create new instant every time when i call that ....so that's means i loss my data that time... – Sanjay Patel May 10 '13 at 16:31
  • 1
    If you add the following attribute to your class it should create a singleton instance: [PartCreationPolicy(CreationPolicy.Shared)] Then any time you call ServiceLocator.GetInstance it will be the same instance. – TrialAndError May 10 '13 at 17:45
0

Alternatively, use the container to store / retrieve the value:

store:

this.container.RegisterInstance<string>("NameOfValue", "abc123");

retrieve:

string nameOfValue = this.container.Resolve<string>("NameOfValue");

The code will have to handle the case where nameOfValue cannot be resolved and, as such, is null.

Andrew
  • 76
  • 1
  • 4