protected virtual void BindEventAggregator(IModuleContext context, IIocContainer container) { IEventAggregator eventAggregator = new EventAggregator(); ServiceProvider.EventAggregator = eventAggregator; container.BindToConstant(eventAggregator); }
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); }
protected virtual void BindOperationCallbackFactory(IModuleContext context, IIocContainer container) { IOperationCallbackFactory callbackFactory = new DefaultOperationCallbackFactory(); ServiceProvider.OperationCallbackFactory = callbackFactory; container.BindToConstant(callbackFactory); }
protected virtual void BindViewModelProvider(IModuleContext context, IIocContainer container) { IViewModelProvider viewModelProvider = new ViewModelProvider(container.GetRoot()); ServiceProvider.ViewModelProvider = viewModelProvider; container.BindToConstant(viewModelProvider); }
protected virtual void BindReflectionManager(IModuleContext context, IIocContainer container) { IReflectionManager reflectionManager = new ExpressionReflectionManager(); ServiceProvider.ReflectionManager = reflectionManager; container.BindToConstant(reflectionManager); }
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); }
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); }
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); }
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); }
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); }
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(); } }
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(); } }
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); } }
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); }
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); }
protected virtual void BindTracer(IModuleContext context, IIocContainer container) { container.BindToConstant <ITracer>(Tracer.Instance); }