当前位置: 首页>>代码示例>>C#>>正文


C# SimpleContainer.GetInstance方法代码示例

本文整理汇总了C#中SimpleContainer.GetInstance方法的典型用法代码示例。如果您正苦于以下问题:C# SimpleContainer.GetInstance方法的具体用法?C# SimpleContainer.GetInstance怎么用?C# SimpleContainer.GetInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimpleContainer的用法示例。


在下文中一共展示了SimpleContainer.GetInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MDIViewModel

 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;
 }
开发者ID:zhangcj,项目名称:Xamarin.Forms.Lagou,代码行数:7,代码来源:MDIViewModel.cs

示例2: TabViewModel

 public TabViewModel(SimpleContainer container) {
     this.Datas = new BindableCollection<Screen>() {
             container.GetInstance<IndexViewModel>(),
             container.GetInstance<SearchViewModel>(),
             container.GetInstance<MyViewModel>(),
             container.GetInstance<FavoritesViewModel>()
         };
 }
开发者ID:zhangcj,项目名称:Xamarin.Forms.Lagou,代码行数:8,代码来源:TabViewModel.cs

示例3: Instances_registered_PerRequest_returns_a_different_instance_for_each_call

        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);
        }
开发者ID:haoasqui,项目名称:Caliburn.Micro,代码行数:9,代码来源:SimpleContainerTests.cs

示例4: ShellViewModel

        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>());
        }
开发者ID:gruan01,项目名称:Lagou.UWP,代码行数:10,代码来源:ShellViewModel.cs

示例5: TabViewModel

        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();
        }
开发者ID:gruan01,项目名称:Discuz.Mobi,代码行数:17,代码来源:TabViewModel.cs

示例6: HomeViewModel

 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);
 }
开发者ID:gruan01,项目名称:Xamarin-Example,代码行数:8,代码来源:HomeViewModel.cs

示例7: Configure

        protected override void Configure()
        {
            _container = new SimpleContainer();

            _container.UseAudioTask();
            _container.UsePlugins();

            _eventAggregator = _container.GetInstance<IEventAggregator>();
        }
开发者ID:sunnycase,项目名称:TomatoMusic,代码行数:9,代码来源:App.cs

示例8: PerRequestTest

		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));

		}
开发者ID:holtsoftware,项目名称:House,代码行数:44,代码来源:SimpleContainerTests.cs

示例9: Singleton_instances_are_the_same_across_parent_and_child

        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);
        }
开发者ID:haoasqui,项目名称:Caliburn.Micro,代码行数:10,代码来源:SimpleContainerTests.cs

示例10: Configure

        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));
        }
开发者ID:Excrulon,项目名称:Tree-of-Savior-Experience-Viewer,代码行数:23,代码来源:AppBootstrapper.cs

示例11: IndexViewModel

        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);
            });
        }
开发者ID:gruan01,项目名称:Lagou.UWP,代码行数:14,代码来源:IndexViewModel.cs

示例12: ConfigureStorageMechanismsAndWorkers

        /// <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));
        }
开发者ID:Geminior,项目名称:Caliburn.Micro.Extras,代码行数:26,代码来源:ModuleBootstrapper.cs

示例13: SingletonTest

		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));
		}
开发者ID:holtsoftware,项目名称:House,代码行数:50,代码来源:SimpleContainerTests.cs

示例14: SearchViewModel

        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>();
        }
开发者ID:zhangcj,项目名称:Xamarin.Forms.Lagou,代码行数:22,代码来源:SearchViewModel.cs

示例15: Run

		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();
		}
开发者ID:holtsoftware,项目名称:House,代码行数:23,代码来源:StartupTask.cs


注:本文中的SimpleContainer.GetInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。