/// <summary> /// Initialises a new instance of the <see cref="ViewManager"/> class, with the given viewFactory /// </summary> /// <param name="config">Configuration object</param> public ViewManager(ViewManagerConfig config) { // Config.ViewAssemblies cannot be null - ViewManagerConfig ensures this if (config.ViewFactory == null) { throw new ArgumentNullException("viewFactory"); } if (config.ViewAssemblies == null) { throw new ArgumentNullException("viewAssemblies"); } this.ViewFactory = config.ViewFactory; this.ViewAssemblies = config.ViewAssemblies; }
/// <summary> /// Carries out default configuration of StyletIoC. Override if you don't want to do this /// </summary> /// <param name="builder">StyletIoC builder to use to configure the container</param> protected virtual void DefaultConfigureIoC(StyletIoCBuilder builder) { // Mark these as weak-bindings, so the user can replace them if they want var viewManagerConfig = new ViewManagerConfig() { ViewFactory = this.GetInstance, ViewAssemblies = builder.Assemblies }; builder.Bind <ViewManagerConfig>().ToInstance(viewManagerConfig).AsWeakBinding(); // Bind it to both IViewManager and to itself, so that people can get it with Container.Get<ViewManager>() builder.Bind <IViewManager>().And <ViewManager>().To <ViewManager>().AsWeakBinding(); builder.Bind <IWindowManagerConfig>().ToInstance(this).DisposeWithContainer(false).AsWeakBinding(); builder.Bind <IWindowManager>().To <WindowManager>().InSingletonScope().AsWeakBinding(); builder.Bind <IEventAggregator>().To <EventAggregator>().InSingletonScope().AsWeakBinding(); builder.Bind <IMessageBoxViewModel>().To <MessageBoxViewModel>().AsWeakBinding(); // Stylet's assembly isn't added to the container, so add this explicitly builder.Bind <MessageBoxView>().ToSelf(); builder.Autobind(); }