/// <summary> /// Establishes the connection and initializes internal structures /// </summary> /// <param name="arg">Settings for the connection, model etc</param> /// <param name="policy">Policy for this datamanager</param> public DataManagerWithPolicy(ConnectionParameters arg, ExecutionPolicy policy) { Contract.Requires(!string.IsNullOrEmpty(arg.connection)); Contract.Requires(!string.IsNullOrEmpty(arg.modelResource)); KConnectionParameters = arg; KPolicy = policy; _creator = new CreationStrategy(KConnectionParameters, KPolicy); switch (KPolicy.PeriodicDisposalStrategy) { case Strategy.DisposeWithThread: _cleaner = new RemoveOnlyWhenThreadIsDead(_map, KPolicy); break; case Strategy.DisposeWhenNotInUse: _cleaner = new RemoveUnused(_map, KPolicy); break; case Strategy.DisposeLeastRecentlyUsed: _cleaner = new RemoveLeastRecentlyUsed(_map, KPolicy); break; default: this._cleaner = new CleaningStrategy(_map, KPolicy); break; } _cleaner.Start(); }
public void CreateView <TView, TViewModel>( ref dynamic view, ref TViewModel viewModel, CreationStrategy viewCreationStrategy = CreationStrategy.Activate, CreationStrategy viewModelCreationStrategy = CreationStrategy.Resolve) { CreateComponent <TView>(ref view, viewCreationStrategy); CreateComponent <TViewModel>(ref viewModel, viewModelCreationStrategy); view.DataContext = viewModel; Attach(view); }
private void CreateComponent(Type componentType, ref object component, CreationStrategy creationStrategy) { switch (creationStrategy) { case CreationStrategy.Activate: component = Activator.CreateInstance(componentType); break; case CreationStrategy.Resolve: component = _exportProvider.GetExportedValue <object>(componentType.FullName); break; case CreationStrategy.Inject: if (component == null) { throw new ArgumentNullException("component"); } break; default: throw new NotSupportedException(); } }
private void CreateComponent <T>(ref dynamic component, CreationStrategy creationStrategy) { switch (creationStrategy) { case CreationStrategy.Activate: component = Activator.CreateInstance <T>(); break; case CreationStrategy.Resolve: component = _exportProvider.GetExportedValue <T>(); break; case CreationStrategy.Inject: if (component == null) { throw new ArgumentNullException("component"); } break; default: throw new NotSupportedException(); } }
public void CreateView( Type viewType, ref FrameworkElement view, Type viewModelType, ref object viewModel, CreationStrategy viewCreationStrategy = CreationStrategy.Activate, CreationStrategy viewModelCreationStrategy = CreationStrategy.Resolve) { object weakView = view; CreateComponent(viewType, ref weakView, viewCreationStrategy); view = (FrameworkElement)weakView; CreateComponent(viewModelType, ref viewModel, viewModelCreationStrategy); view.DataContext = viewModel; Attach(view); }