Exemple #1
0
        protected virtual void BindEventAggregator(IModuleContext context, IIocContainer container)
        {
            IEventAggregator eventAggregator = new EventAggregator();

            ServiceProvider.EventAggregator = eventAggregator;
            container.BindToConstant(eventAggregator);
        }
Exemple #2
0
        public virtual void TestBindToConstantNamed()
        {
            const string named = "named";

            using (IIocContainer iocContainer = GetIocContainer())
            {
                var constValue = new Simple();
                iocContainer.BindToConstant <ISimple>(constValue, named);

                var simple = (ISimple)iocContainer.Get(typeof(ISimple), named);
                simple.ShouldNotBeNull();
                simple.ShouldEqual(constValue);
                iocContainer.Get <ISimple>(named).ShouldEqual(simple);
                iocContainer.Get(typeof(ISimple), named).ShouldEqual(simple);

                Action action = () => iocContainer.Get <ISimple>();
                action.ShouldThrow();
            }

            using (IIocContainer iocContainer = GetIocContainer())
            {
                var constValue = new Simple();
                iocContainer.BindToConstant(typeof(ISimple), constValue, named);

                var simple = (ISimple)iocContainer.Get(typeof(ISimple), named);
                simple.ShouldNotBeNull();
                simple.ShouldEqual(constValue);
                iocContainer.Get <ISimple>(named).ShouldEqual(simple);
                iocContainer.Get(typeof(ISimple), named).ShouldEqual(simple);

                Action action = () => iocContainer.Get <ISimple>();
                action.ShouldThrow();
            }
        }
        protected override void BindReflectionManager(IModuleContext context, IIocContainer container)
        {
            IReflectionManager reflectionManager = new ExpressionReflectionManagerEx();

            ToolkitServiceProvider.ReflectionManager = reflectionManager;
            container.BindToConstant(reflectionManager);
        }
Exemple #4
0
        protected virtual void BindOperationCallbackFactory(IModuleContext context, IIocContainer container)
        {
            IOperationCallbackFactory callbackFactory = new DefaultOperationCallbackFactory();

            ServiceProvider.OperationCallbackFactory = callbackFactory;
            container.BindToConstant(callbackFactory);
        }
Exemple #5
0
        protected virtual void BindViewModelProvider(IModuleContext context, IIocContainer container)
        {
            IViewModelProvider viewModelProvider = new ViewModelProvider(container.GetRoot());

            ServiceProvider.ViewModelProvider = viewModelProvider;
            container.BindToConstant(viewModelProvider);
        }
Exemple #6
0
        protected virtual void BindReflectionManager(IModuleContext context, IIocContainer container)
        {
            IReflectionManager reflectionManager = new ExpressionReflectionManager();

            ServiceProvider.ReflectionManager = reflectionManager;
            container.BindToConstant(reflectionManager);
        }
Exemple #7
0
        protected virtual void BindThreadManager(IModuleContext context, IIocContainer container)
        {
            IThreadManager threadManager = new SynchronousThreadManager();

            ServiceProvider.ThreadManager = threadManager;
            container.BindToConstant(threadManager);
        }
        protected override void BindAttachedValueProvider(IModuleContext context, IIocContainer container)
        {
            IAttachedValueProvider attachedValueProvider = new AttachedValueProvider();

            ToolkitServiceProvider.AttachedValueProvider = attachedValueProvider;
            container.BindToConstant(attachedValueProvider);
        }
Exemple #9
0
        public virtual void TestBindToConstant()
        {
            using (IIocContainer iocContainer = GetIocContainer())
            {
                var constValue = new Simple();
                iocContainer.BindToConstant <ISimple>(constValue);

                var simple = (ISimple)iocContainer.Get(typeof(ISimple));
                simple.ShouldNotBeNull();
                simple.ShouldEqual(constValue);
                iocContainer.Get <ISimple>().ShouldEqual(simple);
                iocContainer.Get(typeof(ISimple)).ShouldEqual(simple);
            }

            using (IIocContainer iocContainer = GetIocContainer())
            {
                var constValue = new Simple();
                iocContainer.BindToConstant(typeof(ISimple), constValue);

                var simple = (ISimple)iocContainer.Get(typeof(ISimple));
                simple.ShouldNotBeNull();
                simple.ShouldEqual(constValue);
                iocContainer.Get <ISimple>().ShouldEqual(simple);
                iocContainer.Get(typeof(ISimple)).ShouldEqual(simple);
            }
        }
        protected override void BindTracer(IModuleContext context, IIocContainer container)
        {
            ITracer tracer = new TracerEx();

            ServiceProvider.Tracer = tracer;
            container.BindToConstant(tracer);
        }
        protected override void BindViewMappingProvider(IModuleContext context, IIocContainer container)
        {
            IViewMappingProvider viewMappingProvider = new ViewMappingProviderEx(context.Assemblies)
            {
                IsSupportedUriNavigation = false
            };

            container.BindToConstant(viewMappingProvider);
        }
Exemple #12
0
        protected virtual void BindValidatorProvider(IModuleContext context, IIocContainer container)
        {
            IValidatorProvider validatorProvider = new ValidatorProvider();

            validatorProvider.Register(typeof(ValidatableViewModelValidator));
            validatorProvider.Register(typeof(DataAnnotationValidatior));
            ServiceProvider.ValidatorProvider = validatorProvider;
            container.BindToConstant(validatorProvider);
        }
Exemple #13
0
        protected virtual void BindViewMappingProvider(IModuleContext context, IIocContainer container)
        {
            var platformType = context.PlatformInfo.Platform;
            IViewMappingProvider mappingProvider = new ViewMappingProvider(context.Assemblies)
            {
                IsSupportedUriNavigation = platformType == PlatformType.WPF
            };

            container.BindToConstant(mappingProvider);
        }
Exemple #14
0
        public virtual void TestCanResolveNamed()
        {
            const string name = "name";

            using (IIocContainer iocContainer = GetIocContainer())
            {
                iocContainer.CanResolve(typeof(ISimple), name).ShouldBeFalse();
                iocContainer.CanResolve <ISimple>(name).ShouldBeFalse();

                iocContainer.BindToConstant <ISimple>(new Simple());

                iocContainer.CanResolve(typeof(ISimple), name).ShouldBeFalse();
                iocContainer.CanResolve <ISimple>(name).ShouldBeFalse();

                iocContainer.BindToConstant <ISimple>(new Simple(), name);

                iocContainer.CanResolve(typeof(ISimple), name).ShouldBeTrue();
                iocContainer.CanResolve <ISimple>(name).ShouldBeTrue();
            }
        }
 /// <summary>
 ///     Sets the current binding.
 /// </summary>
 /// <param name="iocContainer"></param>
 public void SetBinding(IIocContainer iocContainer)
 {
     Should.NotBeNull(iocContainer, "iocContainer");
     if (IsEmpty)
         return;
     if (MethodBindingDelegate != null)
         iocContainer.BindToMethod(MethodBindingDelegate, Lifecycle, Name);
     else if (Type != null)
         iocContainer.Bind(typeof(T), Type, Lifecycle, Name);
     else
         iocContainer.BindToConstant(typeof(T), Instance, Name);
 }
Exemple #16
0
        public virtual void TestCanResolve()
        {
            using (IIocContainer iocContainer = GetIocContainer())
            {
                iocContainer.CanResolve(typeof(ISimple)).ShouldBeFalse();
                iocContainer.CanResolve <ISimple>().ShouldBeFalse();

                iocContainer.BindToConstant <ISimple>(new Simple());

                iocContainer.CanResolve(typeof(ISimple)).ShouldBeTrue();
                iocContainer.CanResolve <ISimple>().ShouldBeTrue();
            }
        }
Exemple #17
0
        public virtual void TestUnbind()
        {
            using (IIocContainer iocContainer = GetIocContainer())
            {
                var constValue = new Simple();
                iocContainer.BindToConstant <ISimple>(constValue);
                iocContainer.Get <ISimple>().ShouldEqual(constValue);

                iocContainer.Unbind(typeof(ISimple));
                Action action = () => iocContainer.Get <ISimple>().ShouldEqual(constValue);
                action.ShouldThrow();
            }
        }
Exemple #18
0
 public void BindToConstant(Type service, object instance, string name = null)
 {
     if (_isMixed && _parentInitialized)
     {
         if (!IsContainerDisposed(_parentContainer))
         {
             _parentContainer.BindToConstant(service, instance, name);
         }
         _iocContainer.BindToConstant(service, instance, name);
     }
     else
     {
         IocContainer.BindToConstant(service, instance, name);
     }
 }
Exemple #19
0
 public void Initialize(PlatformInfo platformInfo, IIocContainer iocContainer, IList <Assembly> assemblies, IDataContext context)
 {
     Should.NotBeNull(platformInfo, nameof(platformInfo));
     Should.NotBeNull(iocContainer, nameof(iocContainer));
     Should.NotBeNull(assemblies, nameof(assemblies));
     if (_isInitialized)
     {
         return;
     }
     _isInitialized = true;
     _platform      = platformInfo;
     _iocContainer  = iocContainer;
     if (context != null)
     {
         Context.Merge(context);
     }
     _iocContainer.BindToConstant <IMvvmApplication>(this);
     OnInitialize(assemblies);
     ToolkitServiceProvider.Initialize(this);
 }
Exemple #20
0
 public void SetBinding(IIocContainer iocContainer)
 {
     Should.NotBeNull(iocContainer, nameof(iocContainer));
     if (IsEmpty)
     {
         return;
     }
     if (MethodBindingDelegate != null)
     {
         iocContainer.BindToMethod(MethodBindingDelegate, Lifecycle, Name, Parameters);
     }
     else if (Type != null)
     {
         iocContainer.Bind(typeof(T), Type, Lifecycle, Name, Parameters);
     }
     else
     {
         iocContainer.BindToConstant(typeof(T), Instance, Name);
     }
 }
 protected override void BindThreadManager(IModuleContext context, IIocContainer container)
 {
     ToolkitServiceProvider.ThreadManager = new ThreadManager(Application.SynchronizationContext);
     container.BindToConstant(ToolkitServiceProvider.ThreadManager);
 }
Exemple #22
0
 protected virtual void BindTracer(IModuleContext context, IIocContainer container)
 {
     container.BindToConstant <ITracer>(Tracer.Instance);
 }