Sunday, August 26, 2012

Translating Structure Map into Autofac

Translating Structure Map into Autofac

I have recently puchased a very good book on MVVM - MVVM Survival Guide For Enterprise Architectures in Silverlight and WPF

Unfortunatly, one of the sections relating to IoC has a lot of code samples for StructureMap which is not available for Silverlight

Can anyone point me to a link that would help me translate Structure Map code to Autofac which is the injection tool I am looking at using

The code uses the factory mehod of creating classes and a bootstrapper

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>();         }     } } 

Paul

Answers & Comments...




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog