Ejemplo n.º 1
0
        /// <summary>
        /// Carries out default configuration of the IoC container. Override if you don't want to do this
        /// </summary>
        protected virtual void DefaultConfigureIoC(IWindsorContainer container)
        {
            var viewManagerConfig = new ViewManagerConfig()
            {
                ViewFactory    = this.GetInstance,
                ViewAssemblies = new List <Assembly>()
                {
                    this.GetType().Assembly
                }
            };

            // Stylet does its own disposal of ViewModels: Castle Windsor shouldn't be doing the same
            // Castle Windsor seems to be very opinionated on this point, insisting that the container
            // should be responsible for disposing all components. This is at odds with Stylet's approach
            // (and indeed common sense).
#pragma warning disable CS0618 // Type or member is obsolete
            container.Kernel.ReleasePolicy = new NoTrackingReleasePolicy();
#pragma warning restore CS0618 // Type or member is obsolete

            container.Register(
                Component.For <IViewManager>().Instance(new ViewManager(viewManagerConfig)),
                Component.For <IWindowManagerConfig>().Instance(this),
                Component.For <IMessageBoxViewModel>().ImplementedBy <MessageBoxViewModel>().LifestyleTransient(),
                // For some reason we need to register the delegate separately?
                Component.For <Func <IMessageBoxViewModel> >().Instance(() => new MessageBoxViewModel()),
                Component.For <MessageBoxView>().LifestyleTransient(),
                Component.For <IWindowManager>().ImplementedBy <WindowManager>().LifestyleSingleton(),
                Component.For <IEventAggregator>().ImplementedBy <EventAggregator>().LifestyleSingleton()
                );
            container.Register(Classes.FromAssembly(this.GetType().Assembly).Pick().LifestyleTransient());
        }
Ejemplo n.º 2
0
 public void SetUp()
 {
     this.config = new ViewManagerConfig()
     {
         ViewFactory = type => null, ViewAssemblies = new List <Assembly>()
     };
     this.viewManager = new AccessibleViewManager(this.config);
 }
Ejemplo n.º 3
0
        public SampleViewManager(ViewManagerConfig config) : base(config)
        {
            var mappings = from type in ViewAssemblies.SelectMany(x => x.GetExportedTypes())
                           let attribute = type.GetCustomAttribute <ViewModelAttribute>()
                                           where attribute != null && typeof(UIElement).IsAssignableFrom(type)
                                           select new { View = type, ViewModel = attribute.ViewModel };

            viewModelToViewMapping = mappings.ToDictionary(x => x.ViewModel, x => x.View);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Carries out default configuration of the IoC container. Override if you don't want to do this
 /// </summary>
 protected virtual void DefaultConfigureIoC(IUnityContainer container)
 {
     var viewManagerConfig = new ViewManagerConfig()
     {
         ViewFactory = this.GetInstance,
         ViewAssemblies = new List<Assembly>() { this.GetType().Assembly }
     };
     var viewManager = new ViewManager(viewManagerConfig);
     // For some reason using ContainerControlledLifetimeManager results in a transient registration....
     container.RegisterInstance<IViewManager>(viewManager);
     container.RegisterInstance<IWindowManager>(new WindowManager(viewManager, () => container.Resolve<IMessageBoxViewModel>(), this));
     container.RegisterInstance<IEventAggregator>(new EventAggregator());
     container.RegisterType<IMessageBoxViewModel, MessageBoxViewModel>(new PerResolveLifetimeManager());
     container.RegisterTypes(AllClasses.FromAssemblies(this.GetType().Assembly), WithMappings.None, WithName.Default, WithLifetime.PerResolve);
 }
Ejemplo n.º 5
0
        /// <summary>
        ///     Carries out default configuration of the IoC container. Override if you don't want to do this
        /// </summary>
        protected virtual void DefaultConfigureIoC(IKernel kernel)
        {
            var viewManagerConfig = new ViewManagerConfig
            {
                ViewFactory    = GetInstance,
                ViewAssemblies = new List <Assembly> {
                    GetType().Assembly
                }
            };

            kernel.Bind <IViewManager>().ToConstant(new ViewManager(viewManagerConfig));

            kernel.Bind <IWindowManagerConfig>().ToConstant(this).InTransientScope();
            kernel.Bind <IWindowManager>().ToMethod(c => new WindowManager(c.Kernel.Get <IViewManager>(), () => c.Kernel.Get <IMessageBoxViewModel>(), c.Kernel.Get <IWindowManagerConfig>())).InSingletonScope();
            kernel.Bind <IEventAggregator>().To <EventAggregator>().InSingletonScope();
            kernel.Bind <IMessageBoxViewModel>().To <MessageBoxViewModel>(); // Not singleton!
        }
Ejemplo n.º 6
0
        public DiiagramrViewManager(ViewManagerConfig config) : base(config)
        {
            ViewFactory = Activator.CreateInstance;

            // todo: automate this
            _viewModelToViewMapping.Add(typeof(ShellViewModel), typeof(ShellView));
            _viewModelToViewMapping.Add(typeof(ProjectScreen), typeof(ProjectScreenView));
            _viewModelToViewMapping.Add(typeof(LibraryManagerWindowViewModel), typeof(LibraryManagerWindowView));
            _viewModelToViewMapping.Add(typeof(LibrarySourceManagerWindowViewModel), typeof(LibrarySourceManagerWindowView));
            _viewModelToViewMapping.Add(typeof(StartScreenViewModel), typeof(StartScreenView));
            _viewModelToViewMapping.Add(typeof(VisualDropStartScreenViewModel), typeof(VisualDropStartScreenView));
            _viewModelToViewMapping.Add(typeof(ProjectExplorer), typeof(ProjectExplorerView));
            _viewModelToViewMapping.Add(typeof(NodePalette), typeof(NodePaletteView));
            _viewModelToViewMapping.Add(typeof(DiagramWellViewModel), typeof(DiagramWellView));
            _viewModelToViewMapping.Add(typeof(Wire), typeof(WireView));
            _viewModelToViewMapping.Add(typeof(Terminal), typeof(TerminalView));
            _viewModelToViewMapping.Add(typeof(OutputTerminal), typeof(OutputTerminalView));
            _viewModelToViewMapping.Add(typeof(InputTerminal), typeof(InputTerminalView));
            _viewModelToViewMapping.Add(typeof(DiiagramrAPI.Diagram.Diagram), typeof(DiagramView));
            _viewModelToViewMapping.Add(typeof(NumberNode), typeof(NumberNodeView));
            _viewModelToViewMapping.Add(typeof(DiagramOutputNode), typeof(DiagramOutputNodeView));
            _viewModelToViewMapping.Add(typeof(DiagramInputNode), typeof(DiagramInputNodeView));
            _viewModelToViewMapping.Add(typeof(DiagramCallNode), typeof(DiagramCallNodeView));
            _viewModelToViewMapping.Add(typeof(ButtonNode), typeof(ButtonNodeView));
            _viewModelToViewMapping.Add(typeof(IndexNode), typeof(IndexNodeView));
            _viewModelToViewMapping.Add(typeof(AndNode), typeof(AndNodeView));
            _viewModelToViewMapping.Add(typeof(AddNode), typeof(AddNodeView));
            _viewModelToViewMapping.Add(typeof(DivideNode), typeof(DivideNodeView));
            _viewModelToViewMapping.Add(typeof(SubtractNode), typeof(SubtractNodeView));
            _viewModelToViewMapping.Add(typeof(MultiplyNode), typeof(MultiplyNodeView));
            _viewModelToViewMapping.Add(typeof(ContextMenuViewModel), typeof(ContextMenuView));
            _viewModelToViewMapping.Add(typeof(ToolbarViewModel), typeof(ToolbarView));
            _viewModelToViewMapping.Add(typeof(LassoNodeSelector), typeof(LassoNodeSelectorView));
            _viewModelToViewMapping.Add(typeof(PointSelector), typeof(PointSelectorView));
            _viewModelToViewMapping.Add(typeof(NodePlacer), typeof(NodePlacerView));
            _viewModelToViewMapping.Add(typeof(NodeDeleter), typeof(NodeDeleterView));
            _viewModelToViewMapping.Add(typeof(NodeDragger), typeof(NodeDraggerView));
            _viewModelToViewMapping.Add(typeof(NodeResizer), typeof(NodeResizerView));
            _viewModelToViewMapping.Add(typeof(DiagramPanner), typeof(DiagramPannerView));
            _viewModelToViewMapping.Add(typeof(DiagramZoomer), typeof(DiagramZoomerView));
            _viewModelToViewMapping.Add(typeof(DiagramInteractionManager), typeof(DiagramInteractionManagerView));
            _viewModelToViewMapping.Add(typeof(TerminalWirer), typeof(TerminalWirerView));
            _viewModelToViewMapping.Add(typeof(HotkeyHelp), typeof(HotkeyHelpView));
            _viewModelToViewMapping.Add(typeof(DiagramRifter), typeof(DiagramRifterView));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Carries out default configuration of the IoC container. Override if you don't want to do this
        /// </summary>
        protected virtual void DefaultConfigureIoC(ContainerBuilder builder)
        {
            var viewManagerConfig = new ViewManagerConfig()
            {
                ViewFactory    = this.GetInstance,
                ViewAssemblies = new List <Assembly>()
                {
                    this.GetType().Assembly
                }
            };

            builder.RegisterInstance <IViewManager>(new ViewManager(viewManagerConfig));

            builder.RegisterInstance <IWindowManagerConfig>(this).ExternallyOwned();
            builder.RegisterType <WindowManager>().As <IWindowManager>().SingleInstance();
            builder.RegisterType <EventAggregator>().As <IEventAggregator>().SingleInstance();
            builder.RegisterType <MessageBoxViewModel>().As <IMessageBoxViewModel>().ExternallyOwned(); // Not singleton!
            builder.RegisterAssemblyTypes(this.GetType().Assembly).ExternallyOwned();
        }
        /// <summary>
        /// Carries out default configuration of the IoC container. Override if you don't want to do this
        /// </summary>
        protected virtual void DefaultConfigureIoC(Container container)
        {
            var viewManagerConfig = new ViewManagerConfig()
            {
                ViewFactory    = this.GetInstance,
                ViewAssemblies = new List <Assembly>()
                {
                    this.GetType().Assembly
                }
            };
            var viewManager = new ViewManager(viewManagerConfig);

            container.RegisterInstance <IViewManager>(viewManager);

            container.RegisterInstance <IWindowManagerConfig>(this);
            container.RegisterInstance <IWindowManager>(new WindowManager(viewManager, container.GetInstance <IMessageBoxViewModel>, this));
            container.Register <IEventAggregator, EventAggregator>(Lifestyle.Singleton);
            container.Register <IMessageBoxViewModel, MessageBoxViewModel>(Lifestyle.Transient); // Not singleton
        }
Ejemplo n.º 9
0
        protected virtual void DefaultConfigureIoC(IServiceCollection services)
        {
            ViewManagerConfig viewManagerConfig = new ViewManagerConfig()
            {
                ViewFactory    = this.GetInstance,
                ViewAssemblies = new List <Assembly>()
                {
                    GetType().Assembly
                }
            };

            services.AddSingleton <IViewManager>(new ViewManager(viewManagerConfig));

            services.AddSingleton <IWindowManagerConfig>(this);
            services.AddSingleton <IWindowManager>(p => new WindowManager(p.GetService <IViewManager>(), p.GetService <IMessageBoxViewModel>, this));
            services.AddSingleton <IEventAggregator, EventAggregator>();
            services.AddTransient <IMessageBoxViewModel, MessageBoxViewModel>();
            services.AddTransient <MessageBoxView>();
        }
Ejemplo n.º 10
0
        protected virtual void DefaultConfigureContainer()
        {
            var viewManagerConfig = new ViewManagerConfig()
            {
                ViewFactory = this.GetInstance,
                ViewAssemblies = new List<Assembly>() { this.GetType().Assembly }
            };
            var viewManager = new ViewManager(viewManagerConfig);
            this.Container.Add(typeof(IViewManager), () => viewManager);

            var windowManager = new WindowManager(viewManager, () => (IMessageBoxViewModel)this.Container[typeof(IMessageBoxViewModel)](), this);
            this.Container.Add(typeof(IWindowManager), () => windowManager);

            var eventAggregator = new EventAggregator();
            this.Container.Add(typeof(IEventAggregator), () => eventAggregator);

            this.Container.Add(typeof(IMessageBoxViewModel), () => new MessageBoxViewModel());
            this.Container.Add(typeof(MessageBoxView), () => new MessageBoxView());
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Carries out default configuration of the IoC container. Override if you don't want to do this
        /// </summary>
        protected virtual void DefaultConfigureIoC(ConfigurationExpression config)
        {
            var viewManagerConfig = new ViewManagerConfig()
            {
                ViewFactory    = this.GetInstance,
                ViewAssemblies = new List <Assembly>()
                {
                    this.GetType().Assembly
                }
            };

            config.For <IViewManager>().Add(new ViewManager(viewManagerConfig));

            // Trick it into not taking ownership of (and disposing) the instance
            config.For <IWindowManagerConfig>().Add(c => this).LifecycleIs <UniquePerRequestLifecycle>();
            config.For <IWindowManager>().Add <WindowManager>().LifecycleIs <SingletonLifecycle>();
            config.For <IEventAggregator>().Add <EventAggregator>().LifecycleIs <SingletonLifecycle>();
            config.For <IMessageBoxViewModel>().Add <MessageBoxViewModel>().LifecycleIs <UniquePerRequestLifecycle>();
            config.Scan(x => x.Assembly(this.GetType().Assembly));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Carries out default configuration of the IoC container. Override if you don't want to do this
        /// </summary>
        protected virtual void DefaultConfigureIoC(IServiceCollection services)
        {
            var viewManagerConfig = new ViewManagerConfig()
            {
                ViewFactory    = this.GetInstance,
                ViewAssemblies = new List <Assembly>()
                {
                    this.GetType().Assembly
                }
            };

            services.AddSingleton <IViewManager>(new ViewManager(viewManagerConfig));
            services.AddTransient <MessageBoxView>();

            services.AddSingleton <IWindowManagerConfig>(this);
            services.AddSingleton <IWindowManager, WindowManager>();
            services.AddSingleton <IEventAggregator, EventAggregator>();
            services.AddTransient <IMessageBoxViewModel, MessageBoxViewModel>(); // Not singleton!
            // Also need a factory
            services.AddSingleton <Func <IMessageBoxViewModel> >(() => new MessageBoxViewModel());
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Carries out default configuration of the IoC container. Override if you don't want to do this
        /// </summary>
        protected virtual void DefaultConfigureIoC(ContainerBuilder builder)
        {
            var viewManagerConfig = new ViewManagerConfig()
            {
                ViewFactory    = this.GetInstance,
                ViewAssemblies = new List <Assembly>()
                {
                    this.GetType().Assembly
                }
            };

            builder.RegisterInstance <IViewManager>(new ViewManager(viewManagerConfig));
            builder.RegisterType <MessageBoxView>();

            builder.RegisterInstance <IWindowManagerConfig>(this).ExternallyOwned();
            builder.RegisterType <WindowManager>().As <IWindowManager>().SingleInstance();
            builder.RegisterType <EventAggregator>().As <IEventAggregator>().SingleInstance();
            builder.RegisterType <MessageBoxViewModel>().As <IMessageBoxViewModel>().ExternallyOwned(); // Not singleton!

            // See https://github.com/canton7/Stylet/discussions/211
            builder.RegisterAssemblyTypes(this.GetType().Assembly).Where(x => !x.Name.Contains("ProcessedByFody")).ExternallyOwned();
        }
Ejemplo n.º 14
0
 public AccessibleViewManager(ViewManagerConfig config)
     : base(config)
 {
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Creates a new instance of <see cref="DiiagramrViewManager"/>.
 /// </summary>
 /// <param name="config">The configuration of the view manager.</param>
 public DiiagramrViewManager(ViewManagerConfig config) : base(config)
 {
     ViewFactory = Activator.CreateInstance;
 }
Ejemplo n.º 16
0
 public ResolvingViewManager(ViewManagerConfig config)
     : base(config)
 {
 }
Ejemplo n.º 17
0
 public ArtemisViewManager(ViewManagerConfig config) : base(config)
 {
 }
Ejemplo n.º 18
0
 public LocatingViewManager(ViewManagerConfig config)
     : base(config)
 {
 }
Ejemplo n.º 19
0
 public CreatingAndBindingViewManager(ViewManagerConfig config)
     : base(config)
 {
 }