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


C# IServiceLocator.ResolveType方法代码示例

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


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

示例1: Configure

        /// <summary>
        /// Configures the specified IoC container with the type resolutions from this library.
        /// </summary>
        public void Configure(IServiceLocator container)
        {
            var cardComparer = new CardComparer();
            container.RegisterInstance<IComparer<Card>>(cardComparer);

            var highCardComparer = new HighCardComparer(cardComparer);
            var handComparer = new HandComparer(
                highCardComparer,
                new PairComparer(highCardComparer),
                new TwoPairComparer(),
                new ThreeOfAKindComparer(highCardComparer),
                new StraightComparer(),
                new FlushComparer(highCardComparer),
                new FullHouseComparer(highCardComparer),
                new FourOfAKindComparer(highCardComparer),
                new StraightFlushComparer());
            container.RegisterInstance<IHandComparer>(handComparer);

            container.RegisterInstance<Func<List<Card>, IHand>>(
                cards => new Hand(
                    cards,
                    cardComparer,
                    handComparer));

            container.RegisterInstance<Func<ICollection<IPlayer>, IGame>>(
                players => new Game(
                    container.ResolveType<IDeckFactory>().CreateStandardDeck(),
                    players,
                    container.ResolveType<IComparer<IPlayer>>(),
                    container.ResolveType<Func<List<Card>, IHand>>()));
        }
开发者ID:Trezamere,项目名称:Poker,代码行数:34,代码来源:Bootstrapper.cs

示例2: Configure

        /// <summary>
        /// Configures the specified IoC container with the type resolutions from this library.
        /// </summary>
        public void Configure(IServiceLocator container)
        {
            container.RegisterInstance<Func<IPlayerConfigurationViewModel>>(() => new PlayerConfigurationViewModel(container.ResolveType<IPlayerConfiguration>()));
            container.RegisterInstance<Func<IRoundResult, IRoundResultViewModel>>(result => new RoundResultViewModel(result));
            container.RegisterInstance<Func<IEnumerable<IPlayer>, IEnumerable<IPlayer>, IRoundResult>>((winners, losers) => new RoundResult(winners, losers));

            var viewModelLocator = container.ResolveType<IViewModelLocator>();
            viewModelLocator.Register(typeof (MainWindow), typeof (MainWindowViewModel));

            var uiVisualizerService = container.ResolveType<IUIVisualizerService>();
            uiVisualizerService.Register(typeof(PlayerConfigurationViewModel), typeof(PlayerConfigurationView));
            uiVisualizerService.Register(typeof(RoundResultViewModel), typeof(RoundResultView));
        }
开发者ID:Trezamere,项目名称:Poker,代码行数:16,代码来源:Bootstrapper.cs

示例3: CatelWebApiDependencyResolver

        public CatelWebApiDependencyResolver(IServiceLocator serviceLocator)
        {
            Argument.IsNotNull(() => serviceLocator);

            _serviceLocator = serviceLocator;
            _typeFactory = serviceLocator.ResolveType<ITypeFactory>();
        }
开发者ID:sk8tz,项目名称:Orc.LicenseManager,代码行数:7,代码来源:CatelWebApiDependencyResolver.cs

示例4: Initialize

        /// <summary>
        /// Initializes the specified service locator.
        /// </summary>
        /// <param name="serviceLocator">The service locator.</param>
        public void Initialize(IServiceLocator serviceLocator)
        {
            Argument.IsNotNull(() => serviceLocator);

#if NET
            var viewModelLocator = serviceLocator.ResolveType<IViewModelLocator>();
            viewModelLocator.Register(typeof(TraceOutputControl), typeof(TraceOutputViewModel));
#endif
        }
开发者ID:justdude,项目名称:DbExport,代码行数:13,代码来源:ExtensionsControlsModule.cs

示例5: DependencyResolver

        /// <summary>
        /// Initializes a new instance of the <see cref="DependencyResolver"/> class.
        /// </summary>
        /// <param name="serviceLocator">The service locator. If <c>null</c>, the <see cref="ServiceLocator.Default"/> will be used.</param>
        public DependencyResolver(IServiceLocator serviceLocator = null)
        {
            if (serviceLocator == null)
            {
                serviceLocator = ServiceLocator.Default;
            }

            _serviceLocator = serviceLocator;
            _typeFactory = serviceLocator.ResolveType<ITypeFactory>();
        }
开发者ID:JaysonJG,项目名称:Catel,代码行数:14,代码来源:DependencyResolver.cs

示例6: OnStartup

        //private static readonly ILog log = LogManager.GetLogger(typeof (Program)) ;
        


        /// <summary>
        /// Raises the <see cref="E:System.Windows.Application.Startup"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.StartupEventArgs"/> that contains the event data.</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            _versionNumber = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            _log.InfoFormat("Starting Safe and Sound 2015 version {0}", _versionNumber);


            base.OnStartup(e);
#if DEBUG
            Catel.Logging.LogManager.RegisterDebugListener();
           
#endif

            StyleHelper.CreateStyleForwardersForDefaultStyles();

            // TODO: Using a custom IoC container like Unity? Register it here:
            //Catel.IoC.ServiceLocator.Instance.RegisterExternalContainer(MyUnityContainer);

            _serviceLocator = ServiceLocator.Default;
            _serviceLocator.RegisterType<IBackupSetService, BackupSetService>();
            _serviceLocator.RegisterType<IMessageBoxService, MessageBoxService>();
            _serviceLocator.RegisterInstance<ILog>(_log);
            var test = _serviceLocator.GetService(typeof(ILog));
            //test.l

            var uiVisualizerService = _serviceLocator.ResolveType<IUIVisualizerService>();
            uiVisualizerService.Register(typeof(BackupSetViewModel), typeof(BackupSetDialog));
            uiVisualizerService.Register(typeof(ExcludedDirectoriesViewModel), typeof(ExcludedDirectoriesWindow));
            uiVisualizerService.Register(typeof(DriveSelectionViewModel), typeof(DriveSelectionWindow));
            uiVisualizerService.Register(typeof(AboutViewModel), typeof(AboutDialog));

            

            

            var typeFactory = this.GetTypeFactory();
            var shellWindowViewModel = typeFactory.CreateInstanceWithParametersAndAutoCompletion<MainWindowViewModel>();
            shellWindowViewModel.OnThemeChanged += shellWindowViewModel_OnThemeChanged;

            new SKnoxConsulting.SafeAndSound.Gui.Views.MainWindow(shellWindowViewModel).ShowDialog();

           // Bootstrapper bootstrapper = new Bootstrapper();
           // bootstrapper.Run();



            
        }
开发者ID:simon-knox,项目名称:SafeAndSound2014,代码行数:55,代码来源:App.xaml.cs

示例7: EditFilterViewModel

        public EditFilterViewModel(FilterSchemeEditInfo filterSchemeEditInfo, IXmlSerializer xmlSerializer, 
            IMessageService messageService, IServiceLocator serviceLocator)
        {
            Argument.IsNotNull(() => filterSchemeEditInfo);
            Argument.IsNotNull(() => xmlSerializer);
            Argument.IsNotNull(() => messageService);
            Argument.IsNotNull(() => serviceLocator);

            PreviewItems = new FastObservableCollection<object>();
            RawCollection = filterSchemeEditInfo.RawCollection;
            EnableAutoCompletion = filterSchemeEditInfo.EnableAutoCompletion;
            AllowLivePreview = filterSchemeEditInfo.AllowLivePreview;
            EnableLivePreview = filterSchemeEditInfo.AllowLivePreview;

            var filterScheme = filterSchemeEditInfo.FilterScheme;

            _originalFilterScheme = filterScheme;
            _xmlSerializer = xmlSerializer;
            _messageService = messageService;
            _serviceLocator = serviceLocator;

            _reflectionService = _serviceLocator.ResolveType<IReflectionService>(filterScheme.Tag);

            DeferValidationUntilFirstSaveCall = true;

            using (var memoryStream = new MemoryStream())
            {
                xmlSerializer.Serialize(_originalFilterScheme, memoryStream);
                memoryStream.Position = 0L;
                FilterScheme = (FilterScheme)xmlSerializer.Deserialize(typeof(FilterScheme), memoryStream);
                FilterScheme.Tag = filterScheme.Tag;
            }

            FilterSchemeTitle = FilterScheme.Title;

            AddGroupCommand = new Command<ConditionGroup>(OnAddGroup);
            AddExpressionCommand = new Command<ConditionGroup>(OnAddExpression);
            DeleteConditionItem = new Command<ConditionTreeItem>(OnDeleteCondition, OnDeleteConditionCanExecute);
        }
开发者ID:dmitry-shechtman,项目名称:Orc.FilterBuilder,代码行数:39,代码来源:EditFilterViewModel.cs

示例8: EditFilterViewModel

        public EditFilterViewModel(FilterSchemeEditInfo filterSchemeEditInfo, IXmlSerializer xmlSerializer,
            IMessageService messageService, IServiceLocator serviceLocator, ILanguageService languageService)
        {
            Argument.IsNotNull(() => filterSchemeEditInfo);
            Argument.IsNotNull(() => xmlSerializer);
            Argument.IsNotNull(() => messageService);
            Argument.IsNotNull(() => serviceLocator);
            Argument.IsNotNull(() => languageService);

            _xmlSerializer = xmlSerializer;
            _messageService = messageService;
            _serviceLocator = serviceLocator;
            _languageService = languageService;

            PreviewItems = new FastObservableCollection<object>();
            RawCollection = filterSchemeEditInfo.RawCollection;
            EnableAutoCompletion = filterSchemeEditInfo.EnableAutoCompletion;
            AllowLivePreview = filterSchemeEditInfo.AllowLivePreview;
            EnableLivePreview = filterSchemeEditInfo.AllowLivePreview;

            var filterScheme = filterSchemeEditInfo.FilterScheme;
            _originalFilterScheme = filterScheme;

            _reflectionService = _serviceLocator.ResolveType<IReflectionService>(filterScheme.Scope);

            DeferValidationUntilFirstSaveCall = true;

            FilterScheme = new FilterScheme
            {
                Scope = _originalFilterScheme.Scope
            };

            AddGroupCommand = new Command<ConditionGroup>(OnAddGroup);
            AddExpressionCommand = new Command<ConditionGroup>(OnAddExpression);
            DeleteConditionItem = new Command<ConditionTreeItem>(OnDeleteCondition, OnDeleteConditionCanExecute);
        }
开发者ID:WildGums,项目名称:Orc.FilterBuilder,代码行数:36,代码来源:EditFilterViewModel.cs

示例9: ViewModelBase

        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModelBase"/> class.
        /// <para/>
        /// This constructor allows the injection of a custom <see cref="IServiceLocator"/>.
        /// </summary>
        /// <param name="serviceLocator">The service locator to inject. If <c>null</c>, the <see cref="Catel.IoC.ServiceLocator.Default"/> will be used.</param>
        /// <param name="supportIEditableObject">if set to <c>true</c>, the view model will natively support models that
        /// implement the <see cref="IEditableObject"/> interface.</param>
        /// <param name="ignoreMultipleModelsWarning">if set to <c>true</c>, the warning when using multiple models is ignored.</param>
        /// <param name="skipViewModelAttributesInitialization">if set to <c>true</c>, the initialization will be skipped and must be done manually via <see cref="InitializeViewModelAttributes"/>.</param>
        /// <exception cref="ModelNotRegisteredException">A mapped model is not registered.</exception>
        /// <exception cref="PropertyNotFoundInModelException">A mapped model property is not found.</exception>
        protected ViewModelBase(IServiceLocator serviceLocator, bool supportIEditableObject = true, bool ignoreMultipleModelsWarning = false,
            bool skipViewModelAttributesInitialization = false)
        {
            UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier<ViewModelBase>();
            ViewModelConstructionTime = FastDateTime.Now;

            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            Log.Debug("Creating view model of type '{0}' with unique identifier {1}", GetType().Name, UniqueIdentifier);

            _ignoreMultipleModelsWarning = ignoreMultipleModelsWarning;

            if (serviceLocator == null)
            {
                serviceLocator = ServiceLocator.Default;
            }

#if !XAMARIN
            DependencyResolver = serviceLocator.ResolveType<IDependencyResolver>();
            _dispatcherService = DependencyResolver.Resolve<IDispatcherService>();
#endif

            // In silverlight, automatically invalidate commands when property changes
#if !WINDOWS_PHONE && !NET35
            ValidateModelsOnInitialization = true;
#endif

            ViewModelCommandManager = MVVM.ViewModelCommandManager.Create(this);
            ViewModelCommandManager.AddHandler(async (viewModel, propertyName, command, commandParameter) =>
            {
                var eventArgs = new CommandExecutedEventArgs((ICatelCommand)command, commandParameter, propertyName);

                CommandExecuted.SafeInvoke(this, eventArgs);
                await CommandExecutedAsync.SafeInvokeAsync(this, eventArgs);
            });

            InvalidateCommandsOnPropertyChanged = true;
            SupportIEditableObject = supportIEditableObject;

            // Temporarily suspend validation, will be enabled at the end of constructor again
            SuspendValidation = true;

            if (!skipViewModelAttributesInitialization)
            {
                InitializeViewModelAttributes();
            }

            ViewModelManager.RegisterViewModelInstance(this);

            object[] interestedInAttributes = GetType().GetCustomAttributesEx(typeof(InterestedInAttribute), true);
            foreach (InterestedInAttribute interestedInAttribute in interestedInAttributes)
            {
                ViewModelManager.AddInterestedViewModelInstance(interestedInAttribute.ViewModelType, this);
            }

            InitializeThrottling();

            // Enable validation again like we promised some lines of code ago
            SuspendValidation = false;

            // As a last step, enable the auditors (we don't need change notifications of previous properties, etc)
            AuditingHelper.RegisterViewModel(this);
        }
开发者ID:Catel,项目名称:Catel,代码行数:78,代码来源:ViewModelBase.cs

示例10: GetRegionInfo

	    /// <summary>
	    /// Checks if the dependency object contains a <see cref="IRegion"/> with the name received as parameter. 
	    /// </summary>
	    /// <param name="this">
	    /// The dependency object.
	    /// </param>
	    /// <param name="regionName">
	    /// The region name.
	    /// </param>
	    /// <param name="serviceLocator">
	    /// The service locator.
	    /// </param>
	    /// <param name="defaultRegionManager">
	    /// The default region manager.
	    /// </param>
	    /// <returns>
	    /// The <see cref="IRegionInfo"/> if the view or nested visual nodes contains a region with the given name, otherwise <c>null</c>.
	    /// </returns>
	    /// <exception cref="System.ArgumentNullException">The <paramref name="this"/> is <c>null</c>.</exception>
	    /// <exception cref="System.ArgumentException">The <paramref name="regionName"/> is <c>null</c> or whitespace.</exception>
	    /// <remarks>
	    /// This method also ensures the setup of the same <see cref="IRegionManager"/> through the visual tree.<br/>
	    /// - If the dependency object has no a region manager the <paramref name="defaultRegionManager"/> will be set. <br/>
	    /// - If a parent dependency object of the give <paramref name="this"/> instance have a established <see cref="IRegionManager"/> then the <paramref name="defaultRegionManager" /> will be ignored.<br/>
	    /// </remarks>
	    public static IRegionInfo GetRegionInfo(this DependencyObject @this, string regionName, IServiceLocator serviceLocator = null, IRegionManager defaultRegionManager = null)
		{
			Argument.IsNotNull("@this", @this);
			Argument.IsNotNullOrWhitespace("regionName", regionName);

		    serviceLocator = serviceLocator ?? ServiceLocator.Default;

			IRegionInfo regionInfo = null;

			var queue = new Queue<DependencyObject>();
			queue.Enqueue(@this);

			defaultRegionManager = @this.GetRegionManager() ?? @this.FindFirstParentRegionManager() ?? defaultRegionManager;

			IRegionManager regionManager = null;
			do 
			{
				var current = queue.Dequeue();

				string currentRegionName = current.GetRegionName();
				if (regionManager == null && !string.IsNullOrEmpty(currentRegionName) && (regionManager = current.GetRegionManager()) == null)
				{
                    current.SetRegionManager(regionManager = defaultRegionManager ?? serviceLocator.ResolveType<IRegionManager>().CreateRegionManager());
				}

				if (currentRegionName == regionName)
				{
					if (regionManager != null)
					{
						current.SetRegionManager(regionManager);
					}

					regionInfo = new RegionInfo(current);
				}
				else
				{
					int childrenCount = VisualTreeHelper.GetChildrenCount(current);
					for (int i = 0; i < childrenCount; i++)
					{
						queue.Enqueue(VisualTreeHelper.GetChild(current, i));
					}
				}
			}
			while (regionInfo == null && queue.Count > 0);

			return regionInfo;
		}
开发者ID:JaysonJG,项目名称:Catel,代码行数:72,代码来源:DependencyObjectExtensions.cs


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