Ejemplo n.º 1
0
        /// <summary>
        /// Reigsters a viewmodel type with a view factory.
        /// </summary>
        /// <param name="viewService"></param>
        /// <param name="viewModelType"></param>
        /// <param name="viewFactory"></param>
        /// <returns></returns>
        public static IViewRegistration Register(this IViewService viewService, Type viewModelType,
                                                 Func <Window> viewFactory)
        {
            if (viewService == null)
            {
                throw new ArgumentNullException(nameof(viewService));
            }
            if (viewModelType == null)
            {
                throw new ArgumentNullException(nameof(viewModelType));
            }
            if (viewFactory == null)
            {
                throw new ArgumentNullException(nameof(viewFactory));
            }

            //Create the registration
            var registration = new ViewRegistration(viewModelType, viewFactory);

            //Add the registration
            viewService.AddRegistration(registration);

            //Return it in case it's needed (most of the time it won't be).
            return(registration);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Register a view type with the view service.
        /// </summary>
        /// <typeparam name="TViewModel"></typeparam>
        /// <typeparam name="TView"></typeparam>
        /// <param name="viewService"></param>
        /// <returns></returns>
        public static IViewRegistration Register <TViewModel, TView>(this IViewService viewService)
            where TView : Window, new()
        {
            if (viewService == null)
            {
                throw new ArgumentNullException(nameof(viewService));
            }

            //Create the registration
            var registration = new ViewRegistration(typeof(TViewModel), () => new TView());

            //Add the registration
            viewService.AddRegistration(registration);

            //Return it in case it's needed (most of the time it won't be).
            return(registration);
        }