public void AutoBindWithNoAssembliesThrows()
        {
            var builder = new StyletIoCBuilder();

            builder.Assemblies = null;
            Assert.Throws <StyletIoCRegistrationException>(() => builder.Autobind());
        }
Esempio n. 2
0
        /// <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 = new List <Assembly>()
                {
                    this.GetType().Assembly
                }
            };

            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();
        }
        public void AutobindingDoesNotBindInterfaceTypes()
        {
            var builder = new StyletIoCBuilder();

            builder.Autobind();
            var ioc = builder.BuildContainer();

            Assert.Throws <StyletIoCRegistrationException>(() => ioc.Get <I1>());
        }
        public void AutobindSearchesPassedAssemblie()
        {
            var builder = new StyletIoCBuilder();

            builder.Assemblies = null;
            builder.Autobind(typeof(StyletIoCAutobindingTests).Assembly);
            var ioc = builder.BuildContainer();

            Assert.IsInstanceOf <C11>(ioc.Get <C11>());
        }
        public void AutobindingBindsGenericTypes()
        {
            var builder = new StyletIoCBuilder();

            builder.Autobind();
            var ioc = builder.BuildContainer();

            var result = ioc.Get <C21 <int> >();

            Assert.IsInstanceOf <C21 <int> >(result);
        }
        public void AutobindingBindsConcreteTypes()
        {
            var builder = new StyletIoCBuilder();

            builder.Autobind(Enumerable.Empty <Assembly>());
            var ioc = builder.BuildContainer();

            var result = ioc.Get <C11>();

            Assert.IsInstanceOf <C11>(result);
        }
        public void AutobindingRespectsKeys()
        {
            var builder = new StyletIoCBuilder();

            builder.Autobind();
            var ioc = builder.BuildContainer();

            var result = ioc.Get <C4>("Key");

            Assert.IsInstanceOf <C4>(result);
        }
        public void AutobindingBindingsCanBeReplaced()
        {
            var builder = new StyletIoCBuilder();

            builder.Autobind();
            builder.Bind <C11>().ToSelf().InSingletonScope();
            var ioc = builder.BuildContainer();

            var result1 = ioc.Get <C11>();
            var result2 = ioc.Get <C11>();

            Assert.AreEqual(result2, result1);
        }
Esempio n. 9
0
        private static IContainer BuildContainer()
        {
            var builder = new StyletIoCBuilder();

            // Autobind the .Services assembly
            builder.Autobind(typeof(DataService).Assembly);

            // Bind settings as singleton
            builder.Bind <SettingsService>().ToSelf().InSingletonScope();

            // Set instance
            return(builder.BuildContainer());
        }
Esempio n. 10
0
        static Container()
        {
            var builder = new StyletIoCBuilder();

            // Autobind services in the .Core assembly
            builder.Autobind(typeof(DataService).Assembly);

            // Bind settings as singleton
            builder.Bind <SettingsService>().ToSelf().InSingletonScope();

            // Set instance
            Instance = builder.BuildContainer();
        }
Esempio n. 11
0
        /// <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 viewManager = new ViewManager(this.GetInstance, new List <Assembly>()
            {
                this.GetType().Assembly
            });

            // Bind it to both IViewManager and to itself, so that people can get it with Container.Get<ViewManager>()
            builder.Bind <IViewManager>().And <ViewManager>().ToInstance(viewManager).AsWeakBinding();

            builder.Bind <IWindowManagerConfig>().ToInstance(this).AsWeakBinding();
            builder.Bind <IWindowManager>().To <WindowManager>().InSingletonScope().AsWeakBinding();
            builder.Bind <IEventAggregator>().To <EventAggregator>().InSingletonScope().AsWeakBinding();
            builder.Bind <IMessageBoxViewModel>().To <MessageBoxViewModel>().AsWeakBinding();

            builder.Autobind();
        }