public MDIViewModel(SimpleContainer container) { this.Master = container.GetInstance<SettingViewModel>(); this.Detail = container.GetInstance<TabViewModel>(); //var vm = container.GetInstance<JobDetailViewModel>(); //vm.ID = 1178538; //this.Detail = vm; }
public TabViewModel(SimpleContainer container) { this.Datas = new BindableCollection<Screen>() { container.GetInstance<IndexViewModel>(), container.GetInstance<SearchViewModel>(), container.GetInstance<MyViewModel>(), container.GetInstance<FavoritesViewModel>() }; }
public void Instances_registered_PerRequest_returns_a_different_instance_for_each_call() { var container = new SimpleContainer(); container.PerRequest<object>(); var instanceA = container.GetInstance(typeof (object), null); var instanceB = container.GetInstance(typeof (object), null); Assert.NotSame(instanceA, instanceB); }
public ShellViewModel(SimpleContainer container, IEventAggregator eventAggregator) { this._eventAggregator = eventAggregator; this.Datas.CollectionChanged += Datas_CollectionChanged; this.Datas.Add(container.GetInstance<IndexViewModel>()); this.Datas.Add(container.GetInstance<DiscoverViewModel>()); this.Datas.Add(container.GetInstance<MyViewModel>()); this.Datas.Add(container.GetInstance<LocalFavoriteViewModel>()); }
public TabViewModel(SimpleContainer container) { this.Container = container; this.Favorites = PropertiesHelper.GetObject<SortedDictionary<int, string>>("Favorites") ?? new SortedDictionary<int, string>(); this.Datas = new BindableCollection<Screen>(); var index = container.GetInstance<ForumIndexViewModel>(); var setting = container.GetInstance<SettingViewModel>(); this.Datas.Add(index); this.Datas.Add(setting); foreach (var kv in this.Favorites) { this.ShowFavorite(kv.Key, kv.Value); } this.RegistMessageCenter(); }
public HomeViewModel(SimpleContainer container) { this.MasterPage = container.GetInstance<MasterViewModel>(); this.DetailPage = new NavigationPage(); this.T = "BBB"; this.NotifyOfPropertyChange(() => this.MasterPage); this.NotifyOfPropertyChange(() => this.DetailPage); this.NotifyOfPropertyChange(() => this.T); }
protected override void Configure() { _container = new SimpleContainer(); _container.UseAudioTask(); _container.UsePlugins(); _eventAggregator = _container.GetInstance<IEventAggregator>(); }
public void PerRequestTest() { SimpleContainer sc = new SimpleContainer(); sc.PerRequest<Test1>(); var result1 = sc.GetInstance<Test1>(); Assert.IsNotNull(result1); var result1a = sc.GetInstance<Test1>(); Assert.IsNotNull(result1a); Assert.AreNotEqual(result1, result1a); bool thrown = false; try { var result2 = sc.GetInstance<Test2>(); } catch(TypeLoadException) { thrown = true; } Assert.IsTrue(thrown); sc.PerRequest<ITest3, Test3>(); var result3 = sc.GetInstance<ITest3>(); Assert.IsNotNull(result3); Assert.IsInstanceOfType(result3, typeof(ITest3)); Assert.IsInstanceOfType(result3, typeof(Test3)); var result4 = sc.GetInstance<Test3>(); Assert.IsNotNull(result4); Assert.IsInstanceOfType(result4, typeof(ITest3)); Assert.IsInstanceOfType(result4, typeof(Test3)); sc.PerRequest<ITest4, Test4>(); var result5 = sc.GetInstance<ITest4>(); Assert.IsNotNull(result5); Assert.IsInstanceOfType(result5, typeof(ITest4)); Assert.IsInstanceOfType(result5, typeof(Test4)); Assert.IsNotNull(result5.Test3); Assert.IsInstanceOfType(result5.Test3, typeof(ITest3)); Assert.IsInstanceOfType(result5.Test3, typeof(Test3)); }
public void Singleton_instances_are_the_same_across_parent_and_child() { var container = new SimpleContainer(); container.Singleton<object>(); var childContainer = container.CreateChildContainer(); var parentInstance = container.GetInstance(typeof (object), null); var childInstance = childContainer.GetInstance(typeof (object), null); Assert.Same(parentInstance, childInstance); }
protected override object GetInstance(Type service, string key) { var instance = _container?.GetInstance(service, key); if (instance != null) { return(instance); } throw new InvalidOperationException("Could not locate any instances."); }
public IndexViewModel(SimpleContainer container, INavigationService ns) { this.NS = ns; this.SearchBarVM = container.GetInstance<SearchBarViewModel>(); this.SearchBarVM.OnSubmit += SearchBarVM_OnSubmit; this.ReloadCmd = new Command(async () => { await this.LoadData(true); }); this.LoadMoreCmd = new Command(async () => { await this.LoadData(false); }); }
protected override void Configure() { container = new SimpleContainer(); container.Singleton<IWindowManager, MetroWindowManager>(); container.Singleton<IEventAggregator, EventAggregator>(); var baseExperienceData = new ExperienceData() { DisplayName = "Base Experience" }; var classExperienceData = new ExperienceData() { DisplayName = "Class Experience" }; IExperienceControl[] baseExperienceControls = GetExperienceControls(baseExperienceData, classExperienceData); ExperienceContainer experienceContainer = new ExperienceContainer(baseExperienceData, classExperienceData, baseExperienceControls); container.Handler<ShellViewModel>(simpleContainer => new ShellViewModel( container.GetInstance<SettingsViewModel>(), experienceContainer, new ExpCardCalculatorViewModel(experienceContainer), container.GetInstance<IWindowManager>())); // TODO - refactor settings view model to just take a collection of menuitems container.Handler<SettingsViewModel>(simpleContainer => new SettingsViewModel(baseExperienceControls)); }
/// <summary> /// Identify, load and configure all instances of <see cref="IStorageMechanism"/> and <see cref="IStorageHandler"/> /// that are defined in the assembly associated with this bootstrapper. /// </summary> /// <param name="phoneContainer">The currently configured <see cref="PhoneContainer"/>.</param> /// <remarks> /// Caliburn Micro will automatically load storage handlers and storage mechanisms from the assemblies configured /// in <see cref="AssemblySource.Instance"/> when <see cref="PhoneContainer.RegisterPhoneServices"/> is first invoked. /// Since the purpose of this bootstrapper is to allow the delayed loading of assemblies, it makes sense to locate /// the storage handlers alongside the view models in the same assembly. /// </remarks> private void ConfigureStorageMechanismsAndWorkers(SimpleContainer phoneContainer) { var coordinator = (StorageCoordinator) (phoneContainer.GetInstance(typeof (StorageCoordinator), null)); var assembly = GetType().Assembly; phoneContainer.AllTypesOf<IStorageMechanism>(assembly); phoneContainer.AllTypesOf<IStorageHandler>(assembly); phoneContainer.GetAllInstances(typeof (IStorageMechanism)). Where(m => ReferenceEquals(m.GetType().Assembly, assembly)). Apply(m => coordinator.AddStorageMechanism((IStorageMechanism) m)); phoneContainer.GetAllInstances(typeof (IStorageHandler)). Where(h => ReferenceEquals(h.GetType().Assembly, assembly)). Apply(h => coordinator.AddStorageHandler((IStorageHandler) h)); }
public void SingletonTest() { SimpleContainer sc = new SimpleContainer(); sc.Singleton<Test1>(); var result = sc.GetInstance<Test1>(); Assert.IsNotNull(result); var result2 = sc.GetInstance<Test1>(); Assert.IsNotNull(result2); Assert.AreEqual(result, result2); sc.Singleton<ITest2, Test2>(); var result3 = sc.GetInstance<ITest2>(); Assert.IsNotNull(result3); Assert.IsInstanceOfType(result3, typeof(ITest2)); Assert.IsInstanceOfType(result3, typeof(Test2)); Assert.AreNotEqual(result2, result3); var result4 = sc.GetInstance<Test2>(); Assert.IsNotNull(result4); Assert.IsInstanceOfType(result4, typeof(ITest2)); Assert.IsInstanceOfType(result4, typeof(Test2)); Assert.AreEqual(result3, result4); sc.Singleton<ITest4, Test4>(); ITest4 result5; bool thrown = false; try { result5 = sc.GetInstance<ITest4>(); } catch (TypeLoadException) { thrown = true; } Assert.IsTrue(thrown); sc.Singleton<ITest3, Test3>(); result5 = sc.GetInstance<ITest4>(); Assert.IsNotNull(result5); Assert.IsInstanceOfType(result5, typeof(ITest4)); Assert.IsInstanceOfType(result5, typeof(Test4)); Assert.IsNotNull(result5.Test3); Assert.IsInstanceOfType(result5.Test3, typeof(ITest3)); Assert.IsInstanceOfType(result5.Test3, typeof(Test3)); }
public SearchViewModel(INavigationService ns, SimpleContainer container) { this.NS = ns; this.Container = container; this.CityVM = container.GetInstance<CitySelectorViewModel>(); this.CityVM.OnCancel += CityVM_OnCancel; this.CityVM.OnChoiced += CityVM_OnChoiced; this.ShowCitySelectorCmd = new Command(() => { this.ToggleCitySelector(true); }); this.SearchCmd = new Command(() => { this.Search(); }); this.LoadMoreCmd = new Command(async () => { await this.LoadData(false); }); this.Datas = new BindableCollection<SearchedItemViewModel>(); }
public void Run(IBackgroundTaskInstance taskInstance) { // // TODO: Insert code to perform background work // // If you start any asynchronous methods here, prevent the task // from closing prematurely by using BackgroundTaskDeferral as // described in http://aka.ms/backgroundtaskdeferral // taskInstance.Canceled += canceled; deferral = taskInstance.GetDeferral(); container = new SimpleContainer(); container.Singleton<ThermostatController>(); container.Singleton<IAppSettings, AppSettings>(); container.Singleton<IServerContext, ServerContext>(); controller = container.GetInstance<ThermostatController>(); timer = new DispatcherTimer(); timer.Tick += timerTick; timer.Interval = TimeSpan.FromSeconds(10); timer.Start(); }
public void Handle(LogOutEvent message) { ActivateItem(_container.GetInstance <LoginViewModel>()); }
protected override void PrepareViewFirst(Frame rootFrame) { _container.RegisterInstance(rootFrame); _container.GetInstance <INavigationService>(); }
public void HandlerTest() { SimpleContainer sc = new SimpleContainer(); ITest1 t1 = null; sc.Handler<ITest1>((i) => { Assert.AreEqual(sc, i); t1 = new Test1(); return t1; }); var result1 = sc.GetInstance<ITest1>(); Assert.IsNotNull(t1); Assert.IsNotNull(result1); Assert.AreEqual(t1, result1); Test2 t2 = null; sc.Handler<ITest2, Test2>(i => { Assert.AreEqual(sc, i); t2 = new Test2(); return t2; }); var result2 = sc.GetInstance<ITest2>(); Assert.IsNotNull(t2); Assert.IsNotNull(result2); Assert.AreEqual(t2, result2); result2 = sc.GetInstance<Test2>(); Assert.IsNotNull(result2); Assert.AreEqual(t2, result2); }
public void Deposite() { ActivateItem(_container.GetInstance <DepositeViewModel>()); _eventAggregator.PublishOnBackgroundThread(MyPerson); }
protected override object GetInstance(Type service, string key) => _container.GetInstance(service, key);
public void InstanceTest() { SimpleContainer sc = new SimpleContainer(); ITest1 ti = new Test1(); sc.Instance<ITest1, Test1>(ti); var result = sc.GetInstance<ITest1>(); Assert.AreEqual(result, ti); var result2 = sc.GetInstance<Test1>(); Assert.AreEqual(result2, ti); Test2 t2 = new Test2(); sc.Instance(t2); var result3 = sc.GetInstance<Test2>(); Assert.AreEqual(result3, t2); Test3 t3 = new Tests.Test3(); sc.Instance<ITest3>(t3); var result4 = sc.GetInstance<ITest3>(); Assert.AreEqual(result4, t3); }
protected override object GetInstance(Type service, string key) { // when we pass a type and a name we will get an instance // for example ShellViewModel return(_container.GetInstance(service, key)); }
private void GetLoginViewModel() { ActivateItemAsync(_simpleContainer.GetInstance <LoginViewModel>()); }
public static T Get <T>(this SimpleContainer container) { return((T)container.GetInstance(typeof(T), null)); }
public ActivityScreen GetScreen(Screens screen) { switch (screen) { case Screens.DashBoard: return(_container.GetInstance <DashBoardViewModel>()); case Screens.Login: return(_container.GetInstance <LoginScreenViewModel>()); case Screens.OrderEditor: return(_container.GetInstance <OrderEditorViewModel>()); case Screens.ClientDictionary: return(_container.GetInstance <ClientDictionaryViewModel>()); case Screens.ClientEditor: return(_container.GetInstance <ClientEditorViewModel>()); case Screens.About: return(_container.GetInstance <AboutViewModel>()); case Screens.Settings: return(_container.GetInstance <SettingsViewModel>()); case Screens.EmployeeDictionary: return(_container.GetInstance <EmployeeDictionaryViewModel>()); case Screens.Analytics: return(_container.GetInstance <AnalyticsViewModel>()); case Screens.EmployeeEditor: return(_container.GetInstance <EmployeeEditorViewModel>()); case Screens.SubsidiaryDictionary: return(_container.GetInstance <SubsidiaryDictionaryViewModel>()); case Screens.SubsidiaryEditor: return(_container.GetInstance <SubsidiaryEditorViewModel>()); case Screens.DiscountSystem: return(_container.GetInstance <DiscountSystemViewModel>()); case Screens.CarDictionary: return(_container.GetInstance <CarDictionaryViewModel>()); case Screens.CarEditor: return(_container.GetInstance <CarEditorViewModel>()); case Screens.ClothKindEditor: return(_container.GetInstance <ClothKindDictionaryViewModel>()); case Screens.OrderDictionary: return(_container.GetInstance <OrderDictionaryViewModel>()); default: throw new ArgumentOutOfRangeException(nameof(screen), screen, null); } }
/// <summary> /// Gets the instance. /// </summary> /// <param name="serviceType">Type of the service.</param> /// <param name="key">The key.</param> /// <returns>System.Object.</returns> /// <exception cref="System.InvalidOperationException">Could not locate any instances.</exception> protected override object GetInstance(Type serviceType, string key) { return(_container.GetInstance(serviceType, key) ?? throw new InvalidOperationException("Could not locate any instances.")); }
public static T Get <T>(this SimpleContainer container, string key) { return((T)container.GetInstance(typeof(T), key)); }
public void Instances_can_be_found_by_name_only() { var container = new SimpleContainer(); container.RegisterPerRequest(typeof(object), "AnObject", typeof(object)); Assert.NotNull(container.GetInstance(null, "AnObject")); }
protected override void OnActivate() { Items.Clear(); var opdrachtenCount = gespeeldeOpdrachten.Count(); for (var i = 0; i < opdrachtenCount; i++) { var opdrachtData = gespeeldeOpdrachten[i]; var jijmol = container.GetInstance <QuizBenJijDeMolViewModel>(); jijmol.Naam = Naam; jijmol.OpdrachtData = opdrachtData; jijmol.DoNext = model => { if (model.IsDeMol) { var x = Items.SkipWhile(item => !Equals(item, ActiveItem)).Skip(1) .FirstOrDefault(y => y is QuizVragenViewModel) as QuizVragenViewModel; x.IsDeMol = true; ActivateItem(x); } else { var x = Items.SkipWhile(item => !Equals(item, ActiveItem)).Skip(1) .FirstOrDefault(y => y is QuizWieIsDeMolViewModel) as QuizWieIsDeMolViewModel; ActivateItem(x); } }; Items.Add(jijmol); var wieisdemol = container.GetInstance <QuizWieIsDeMolViewModel>(); wieisdemol.Naam = Naam; wieisdemol.OpdrachtData = opdrachtData; wieisdemol.DoNext = model => { var x = Items.SkipWhile(item => !Equals(item, ActiveItem)).Skip(1) .FirstOrDefault(y => y is QuizVragenViewModel) as QuizVragenViewModel; x.IsDeMol = false; x.DeMolIs = model.DeMolIs; ActivateItem(x); }; Items.Add(wieisdemol); var vragen = container.GetInstance <QuizVragenViewModel>(); var vragenCodes = VragenCodesFromGespeeldeOpdracht(opdrachtData); vragen.VragenCodes = vragenCodes; vragen.OpdrachtId = opdrachtData.Opdracht; vragen.Naam = Naam; vragen.DoNext = model2 => { var isLast = !Items.SkipWhile(item => !Equals(item, ActiveItem)).Skip(1).Any(); if (isLast) { var adminData = Util.GetAdminDataOfSelectedDag(container); adminData.HeeftQuizGespeeld.Add(new SpelerInfo { Naam = Naam }); Util.SafeAdminData(container, adminData); var q = Parent as QuizViewModel; q.StartSmoel(); } else { ActivateItem(Items.SkipWhile(item => !Equals(item, ActiveItem)).Skip(1).FirstOrDefault()); } }; Items.Add(vragen); } if (!Items.Any()) { var boodschap = container.GetInstance <BoodschapViewModel>(); boodschap.Text = "Er zijn geen opdrachten gespeeld vandaag."; Items.Add(boodschap); } ActivateItem(Items.First()); base.OnActivate(); }
public SearchBarViewModel(SimpleContainer container) { this.CitySelectorVM = container.GetInstance<CitySelectorViewModel>(); this.CitySelectorVM.OnChoiced += CitySelectorVM_OnChoiced; this.CitySelectorVM.OnCancel += CitySelectorVM_OnCancel; }
private void FixCM(SimpleContainer container) { var f = ViewLocator.LocateTypeForModelType; ViewLocator.LocateTypeForModelType = (type, bindable, context) => { return f(type, bindable, context ?? Device.OS) ?? f(type, bindable, context); }; var ps = string.Join("|", Enum.GetNames(typeof(TargetPlatform)).Select(p => string.Format(@"\.{0}", p))); var rx = new Regex(string.Format("({0})$", ps)); var f2 = ViewModelLocator.LocateForViewType; ViewModelLocator.LocateForViewType = viewType => { var vm = f2(viewType); if (vm == null) { if (rx.IsMatch(viewType.FullName)) { //if (viewType.FullName.EndsWith(".Windows")) { var vmTypeName = rx.Replace(viewType.FullName, "ViewModel") .Replace(".Views.", ".ViewModels."); var vmType = Type.GetType(vmTypeName); if (vmType != null) { return container.GetInstance(vmType, null); } } } return vm; }; }
protected override object GetInstance(Type service, string key) { return(container.GetInstance(service, key)); }
public void An_instance_is_returned_for_the_type_specified_if_found() { var container = new SimpleContainer(); container.PerRequest<object>(); Assert.NotNull(container.GetInstance(typeof(object), null)); }
public static SimpleContainer InstantiateInstancesOf <TService>(this SimpleContainer container) { return(AllTypesOf <TService>(container, type => container.GetInstance(type, null))); }
public void Instances_registed_Singleton_return_the_same_instance_for_each_call() { var container = new SimpleContainer(); container.Singleton<object>(); var instanceA = container.GetInstance(typeof(object), null); var instanceB = container.GetInstance(typeof(object), null); Assert.Same(instanceA, instanceB); }
public void RechargeAccount() { var accountRechargeVM = _container.GetInstance <AccountRechargeViewModel>(); _windowManager.ShowDialog(accountRechargeVM); }
public static ChangeReason RequestReason(SimpleContainer container, IWindowManager windowManager, int defaultReasonNumber) { var specify = (SpecifyValueViewModel)container.GetInstance(typeof(SpecifyValueViewModel), "SpecifyValueViewModel"); specify.Title = "Log Reason"; specify.Message = "Please specify a reason for this change:"; specify.ShowComboBox = true; specify.ComboBoxItems = ChangeReason.ChangeReasons.Where(x => !x.Reason.StartsWith("[Importer]")).Select(x => x.Reason).ToList(); specify.ShowCancel = true; var defaultReason = ChangeReason.ChangeReasons.FirstOrDefault(x => x.ID == defaultReasonNumber); if (defaultReason != null) specify.ComboBoxSelectedIndex = specify.ComboBoxItems.IndexOf(defaultReason.Reason); windowManager.ShowDialog(specify); if (specify.WasCanceled) return null; return ChangeReason.ChangeReasons.FirstOrDefault(x => x.Reason == specify.Text) ?? ChangeReason.AddNewChangeReason(specify.Text); }
public static void ShowAddNewUser(SimpleContainer container, IWindowManager windowManager) { var askUser = container.GetInstance(typeof(SpecifyValueViewModel), "SpecifyValueViewModel") as SpecifyValueViewModel; if (askUser == null) { Common.ShowMessageBox("EPIC FAIL", "RUN AROUND WITH NO REASON", false, true); return; } askUser.ShowComboBox = false; askUser.Message = "Please enter your username (this will be used to log changes made to the data)"; askUser.Title = "Add New User"; windowManager.ShowDialog(askUser); var user = askUser.Text; if (!String.IsNullOrWhiteSpace(user)) { UserHelper.Add(user); } }
public MDIViewModel(SimpleContainer container) { this.Master = container.GetInstance<SettingViewModel>(); this.Detail = container.GetInstance<TabViewModel>(); }