Example #1
0
        protected override void Configure()
        {
            //异常捕获
            Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException       += CurrentDomain_UnhandledException;

            //映射公用库中的vm
            string dzyView      = "DZY.DotNetUtil.WPF.Views";
            string dzyViewModel = "DZY.DotNetUtil.WPF.ViewModels";

            ViewLocator.AddSubNamespaceMapping(dzyViewModel, dzyView, "Control");
            ViewModelLocator.AddSubNamespaceMapping(dzyView, dzyViewModel);

            //初始化ioc容器
            container = new SimpleContainer();

            container.
            Singleton <IEventAggregator, EventAggregator>().
            Singleton <IWindowManager, WindowManager>().
            Singleton <CountDownViewModel>().
            Singleton <ContextMenuViewModel>(nameof(ContextMenuViewModel)).
            Singleton <EyeNurseService>().
            PerRequest <LockScreenViewModel>().
            PerRequest <SettingViewModel>().
            Instance(container);
        }
Example #2
0
        public AppBootstrapper()
        {
            //var hostExePath = $"{Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName}\\NorthwindBusinessPartnerIndex.Host\\bin\\Debug\\NorthwindBusinessPartnerIndex.Host.exe";
            //Process.Start(hostExePath);

            ViewLocator.AddSubNamespaceMapping("NorthwindBusinessPartnerIndex.Client.UI.ViewModels", "NorthwindBusinessPartnerIndex.Client.UI.Views");

            Container = BuildContainer();

            Initialize();
        }
Example #3
0
        protected virtual void ConfigureBootstrapper()
        {
            var config = new TypeMappingConfiguration
            {
                //DefaultSubNamespaceForViews = typeof(ShellView).Namespace,
                //DefaultSubNamespaceForViewModels = typeof(ShellViewModel).Namespace

                //UseNameSuffixesInMappings = false
            };

            ViewLocator.AddSubNamespaceMapping("*.ViewModels", "*.Views");
            //ViewModelLocator.ConfigureTypeMappings(config);
        }
Example #4
0
        /// <summary>
        /// Configures the View-ViewModel type- and
        /// namespace mappings.
        /// </summary>
        protected override void Configure()
        {
            TypeMappingConfiguration map = new TypeMappingConfiguration()
            {
                DefaultSubNamespaceForViewModels = "Scrubbler.ViewModels",
                DefaultSubNamespaceForViews      = "Scrubbler.Views"
            };

            ViewLocator.ConfigureTypeMappings(map);
            ViewLocator.AddSubNamespaceMapping("Scrubbler.ViewModels.ScrobbleViewModels", "Scrubbler.Views.ScrobbleViews");
            ViewLocator.AddSubNamespaceMapping("Scrubbler.ViewModels.SubViewModels", "Scrubbler.Views.SubViews");
            ViewModelLocator.ConfigureTypeMappings(map);
        }
Example #5
0
        protected override void Configure()
        {
            TypeMappingConfiguration map = new TypeMappingConfiguration()
            {
                DefaultSubNamespaceForViewModels = "Last.fm_Scrubbler_WPF.ViewModels",
                DefaultSubNamespaceForViews      = "Last.fm_Scrubbler_WPF.Views"
            };

            ViewLocator.ConfigureTypeMappings(map);
            ViewLocator.AddSubNamespaceMapping("fm_Scrubbler_WPF.ViewModels.ScrobbleViewModels", "fm_Scrubbler_WPF.Views.ScrobbleViews");
            ViewLocator.AddSubNamespaceMapping("fm_Scrubbler_WPF.ViewModels.SubViewModels", "fm_Scrubbler_WPF.Views.SubViews");
            ViewModelLocator.ConfigureTypeMappings(map);

            _container = new SimpleContainer();
            _container.Singleton <IWindowManager, WindowManager>();
            _container.Singleton <ILastFMClientFactory, LastFMClientFactory>();
            _container.Singleton <IScrobblerFactory, ScrobblerFactory>();
            _container.PerRequest <MainViewModel>();
        }
Example #6
0
        /// <summary>
        /// By default, we are configured to use MEF
        /// </summary>
        protected override void Configure()
        {
            // CMContrib Config stuff
            FrameworkExtensions.Message.Attach.AllowExtraSyntax(MessageSyntaxes.SpecialValueProperty | MessageSyntaxes.XamlBinding);
            FrameworkExtensions.ActionMessage.EnableFilters();
            FrameworkExtensions.ViewLocator.EnableContextFallback();
            Localizer.CustomResourceManager = Properties.Demo.ResourceManager;

            // Return a generic sample view if the sample doesn't provide a custom view
            var baseLocate = ViewLocator.LocateTypeForModelType;

            ViewLocator.LocateTypeForModelType = (type, dependencyObject, context) =>
            {
                var baseView = baseLocate(type, dependencyObject, context);
                if (baseView == null && type.GetInterfaces().Contains(typeof(ISample)))
                {
                    return(typeof(GenericSampleView));
                }
                return(baseView);
            };
            // Namespace mapping for custom dialog view
            ViewLocator.AddSubNamespaceMapping("Dialogs", "Demo.Views");
            // or alternatively
            // ViewLocator.AddNamespaceMapping("Caliburn.Micro.Contrib.Dialogs", "Caliburn.Micro.Contrib.Demo.Views");

            var catalog = new AggregateCatalog(
                AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>()
                );

            container = new CompositionContainer(catalog);

            var batch = new CompositionBatch();

            batch.AddExportedValue <IWindowManager>(new WindowManager());
            batch.AddExportedValue <IEventAggregator>(new EventAggregator());
            batch.AddExportedValue(container);
            batch.AddExportedValue(catalog);

            container.Compose(batch);

            LogManager.GetLog = t => new ConsoleLog(t);
        }
Example #7
0
        protected override void Configure()
        {
            //  configure container
            var builder = new ContainerBuilder();

            //  register view models
            builder.RegisterAssemblyTypes(AssemblySource.Instance.ToArray())
            //  must be a type that ends with ViewModel
            .Where(type => type.Name.EndsWith("ViewModel"))
            //  must implement INotifyPropertyChanged (deriving from PropertyChangedBase will statisfy this)
            .Where(type => type.GetInterface(typeof(System.ComponentModel.INotifyPropertyChanged).Name) != null)
            //  registered as self
            .AsSelf()
            .PropertiesAutowired()
            //  always create a new one
            .InstancePerDependency();

            //  register views
            builder.RegisterAssemblyTypes(AssemblySource.Instance.ToArray())
            //  must be a type that ends with View
            .Where(type => type.Name.EndsWith("View"))
            //  registered as self
            .AsSelf()
            //  always create a new one
            .InstancePerDependency();

            //  register the single window manager for this container
            builder.Register <IWindowManager>(c => new WindowManager()).InstancePerLifetimeScope();
            //  register the single event aggregator for this container
            builder.Register <IEventAggregator>(c => new EventAggregator()).InstancePerLifetimeScope();

            ConfigureContainer(builder);

            Container = builder.Build();

            ViewLocator.AddSubNamespaceMapping("ViewModel", "View");
        }
Example #8
0
        protected override void Configure()
        {
            TypeMappingConfiguration map = new TypeMappingConfiguration()
            {
                DefaultSubNamespaceForViewModels = "Scrubbler.ViewModels",
                DefaultSubNamespaceForViews      = "Scrubbler.Views"
            };

            ViewLocator.ConfigureTypeMappings(map);
            ViewLocator.AddSubNamespaceMapping("Scrubbler.ViewModels.ScrobbleViewModels", "Scrubbler.Views.ScrobbleViews");
            ViewLocator.AddSubNamespaceMapping("Scrubbler.ViewModels.SubViewModels", "Scrubbler.Views.SubViews");
            ViewModelLocator.ConfigureTypeMappings(map);

            _container = new SimpleContainer();
            _container.Singleton <IWindowManager, WindowManager>();
            _container.Singleton <IExtendedWindowManager, ExtendedWindowManager>();
            _container.Singleton <ILastFMClientFactory, LastFMClientFactory>();
            _container.Singleton <IScrobblerFactory, ScrobblerFactory>();
            _container.Singleton <ILocalFileFactory, LocalFileFactory>();
            _container.Singleton <IFileOperator, FileOperator>();
            _container.Singleton <IDirectoryOperator, DirectoryOperator>();
            _container.Singleton <ISerializer <User>, DCSerializer <User> >();
            _container.PerRequest <MainViewModel>();
        }