Quantcast
Channel: Caliburn.Micro: Xaml Made Easy
Viewing all articles
Browse latest Browse all 1760

New Post: Get ViewModel through IoC isssue

$
0
0

I'm newcommer in Caliburn.

You can see ViewModel code below.

[Export(typeof(CardValidatingViewModel))]publicclass CardValidatingViewModel
{
       [ImportingConstructor]public CardValidatingViewModel(string password)
        {            
        }
}

Associated view code:

  publicsealedpartialclass CardValidatingView {public CardValidatingView() { InitializeComponent(); CardValidatingViewModel viewModel = IoC.Get<CardValidatingViewModel>();; viewModel.ApplicationLaunchBranch(); } }

Namespaces are correct. IoC.Get() throws Exception from the code of Bootstrapper:

publicclass Bootstrapper : Bootstrapper<PrimaryLaunchViewModel>
    {private CompositionContainer container;protectedoverridevoid Configure()
        {
            container = new CompositionContainer(new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()));

            CompositionBatch batch = new CompositionBatch();

            batch.AddExportedValue<IWindowManager>(new WindowManager());
            batch.AddExportedValue<IEventAggregator>(new EventAggregator());    
            batch.AddExportedValue(container);
            container.Compose(batch);
        }protectedoverrideobject GetInstance(Type serviceType, string key)
        {string contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key;var exports = container.GetExportedValues<object>(contract);if (exports.Count() > 0)
            {return exports.First();
            }thrownew Exception(string.Format("Could not locate any instances of contract {0}.", contract));
        }protectedoverride IEnumerable<object> GetAllInstances(Type serviceType)
        {return container.GetExportedValues<object>(AttributedModelServices.GetContractName(serviceType));
        }protectedoverridevoid BuildUp(object instance)
        {
            container.SatisfyImportsOnce(instance);
        }
    }
IoC.Get() could not locate any instances of ViewModel. Without IoC.Get() everything is fine.
I mean see the View. But I really need to get the ViewModel. What is the problem?


Viewing all articles
Browse latest Browse all 1760

Trending Articles