Unity and multiple constructors

Dec 19, 2009 at 1:59 PM

Hi,

  How can one ensure that a particular constructor of your class is called:  I have two constructors:

(I need to ensure my second constructor is invoked.)

 
public ProductCollectionViewModel()
        {

     
        }

        public ProductCollectionViewModel(IInventoryDataService dataService,
                                          IEventAggregator eventAggregator,
                                          IRegionManager regionManager,
                                          IUnityContainer container)
            : base()
        {

            this.dataService = dataService;
            this.regionManager = regionManager;
            this.container = container;
            this.eventAggregator = eventAggregator;
            eventAggregator.GetEvent<AppStatusMessageEvent>().Publish("Loading Categories...");
            this.SelectProductCommand = new DelegateCommand<Product>(this.SelectProduct);
         
            List<ProductCategory> prodCats = dataService.GetAllCategories();
            prodCats.Sort((x, y) => string.Compare(x.Name, y.Name));
            categories = new PopUpCollection<ProductCategory>();
            foreach (var pc in prodCats)
                categories.Add(pc);

            selectedProduct = new Product();
            //SetValue(ShowMessageCommandProperty, new ShowMessageBoxCommand(this));
            //SetValue(ItemCommandProperty, new ItemSelectedCommand(this));
        }

Dec 20, 2009 at 12:41 AM
Edited Dec 20, 2009 at 12:42 AM

See http://msdn.microsoft.com/en-us/library/dd203208.aspx for the API, or http://msdn.microsoft.com/en-us/library/dd203129.aspx for the attribute approach, or http://msdn.microsoft.com/en-us/library/dd203230.aspx for the config file.