I recently published a very good book about MVVM - MVVM Survival Guide for Enterprise Architectures in Silverlight and WPF
Unfortunately, in one of the sections related to IoC, there are many sample code for StructureMap, which is not available for Silverlight
Can someone point me to a link that will help me translate the Structure Map code into Autofac, which is the injection tool I use
The code uses the factory method for creating classes and the loader
using Northwind.ViewModel; using StructureMap; namespace Northwind.UI.WPF { public class BootStrapper { public MainWindowViewModel MainWindowViewModel { get { return ObjectFactory .GetInstance<MainWindowViewModel>(); } } public BootStrapper() { ObjectFactory.Initialize( o => o.Scan( a => { a.WithDefaultConventions(); a.AssembliesFromApplicationBaseDirectory( d => d.FullName .StartsWith("Northwind")); a.LookForRegistries(); })); } } using StructureMap; namespace Northwind.ViewModel { public class CustomerDetailsViewModelFactory : ICustomerDetailsViewModelFactory { private readonly IContainer _container; public CustomerDetailsViewModelFactory( IContainer container) { _container = container; } public CustomerDetailsViewModel CreateInstance( string customerID) { return _container .With("customerID") .EqualTo(customerID) .GetInstance<CustomerDetailsViewModel>(); } } }
Floor
source share