Passing an Oject from main module to the others

Topics: Bootstrappers & IoC
Jan 19, 2012 at 11:23 AM

Hello,

I've stared splitting my WPF code into smaller modules... I've got a problem about an object wich contains some specific value as userID,roles and so on...  is there a way of exporting that object somewhere and get it via IoC?

I've tried doing so

 

 protected override void InitializeCompositionBatch(CompositionBatch batch)
        {
            base.InitializeCompositionBatch(batch);

            var catalog = new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>());
            container = new CompositionContainer(catalog);

            var provider = new EntityManagerProvider();
      
[...]

           batch.AddExportedValue<IAuthenticationService>(admin);

            batch.AddExportedValue(container);

            batch.AddExportedValue(domeViewModelFactory);

            batch.AddExportedValue(App.LoggedUser); //here it's still null, I set it after a LoginViewModel's action
            container.Compose(batch);
        }

 

and getting it via IoC

 

  [Export]
    public class myViewModel : Screen
    {
        [Import]
        MyUser _myUser;

        [ImportingConstructor]
        public TitoliDepositatiViewModel(IApplicationRepository repository,MyUser myUser)
            : base(repository)
        {
           _myUser= myUser;
            base.DisplayName = ExtendedDescription;
            //Date = App.DataLavorativa;
            Date = DateTime.Now.Date;
        }

 

but it's still null...what am I doing wrong?

Thanks

Coordinator
Jan 19, 2012 at 1:29 PM
Edited Jan 19, 2012 at 1:30 PM

I recommend creating an different object which has a User property so that you can register it at the beginning with AddExportedValue. Then you can just change the User property in your login view model.

Jan 19, 2012 at 1:33 PM

Hello EisenbergEffect,

for now I've fixed using the Manager.Principal that reflect 100% the MyUser class, btw if I'll need to pass items across project I'll so so,

Thanks!