本文整理汇总了C#中IServiceLocator.GetAllInstances方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceLocator.GetAllInstances方法的具体用法?C# IServiceLocator.GetAllInstances怎么用?C# IServiceLocator.GetAllInstances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceLocator
的用法示例。
在下文中一共展示了IServiceLocator.GetAllInstances方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteCore
/// <summary>
/// Executes the task.
/// </summary>
/// <param name="serviceLocator">The service locator.</param>
protected override void ExecuteCore(IServiceLocator serviceLocator)
{
IEnumerable<IModelMetadataConfiguration> configurations = serviceLocator.GetAllInstances<IModelMetadataConfiguration>();
IModelMetadataRegistry registry = serviceLocator.GetInstance<IModelMetadataRegistry>();
configurations.Each(configuration => registry.Register(configuration.ModelType, configuration.Configurations));
ModelMetadataProviders.Current = serviceLocator.GetInstance<CompositeModelMetadataProvider>();
// We have to make sure that custom provider will appear first,
// otherwise it will return wrong validation messages.
serviceLocator.GetAllInstances<ModelValidatorProvider>()
.Each(provider => ModelValidatorProviders.Providers.Insert(0, provider));
}
示例2: DataProviderViewModel
public DataProviderViewModel(ExperimentViewModel experimentViewModel, IServiceLocator serviceLocator)
{
this.serviceLocator = serviceLocator;
_experimentViewModel = experimentViewModel;
ViewModel = experimentViewModel;
dataProviders = serviceLocator.GetAllInstances<IDataProvider>().ToList();
selectedDataProvider = dataProviders.First();
}
示例3: DocumentManager
public DocumentManager(IEventAggregator eventAggregator, IServiceLocator serviceLocator)
{
Save = new DelegateCommand<string>(OnSave, CanSave);
Close = new DelegateCommand<string>(OnClose, CanClose);
New = new DelegateCommand<string>(OnNew, CanNew);
_experiments = new List<ExperimentBase>();
_eventAggregator = eventAggregator;
_serviceLocator = serviceLocator;
_experimentTypes = _serviceLocator.GetAllInstances<IExperimentType>();
}
示例4: ConvertExperimentReferencesToExperiments
public static void ConvertExperimentReferencesToExperiments(ProjectBase project, IServiceLocator serviceLocator)
{
project.Experiments.Clear();
IEnumerable<IExperimentType> experimentTypes = serviceLocator.GetAllInstances<IExperimentType>();
foreach (MassSpecStudio.Core.Domain.ProjectBase.ExperimentReference experimentReference in project.ExperimentReferences)
{
IExperimentType experimentType = experimentTypes.Where(item => item.ExperimentType == experimentReference.ExperimentType).FirstOrDefault();
project.Experiments.Add(new Experiment(experimentReference.Name, project, experimentType));
}
}
示例5: ExecuteCore
/// <summary>
/// Executes the task.
/// </summary>
/// <param name="serviceLocator">The service locator.</param>
protected override void ExecuteCore(IServiceLocator serviceLocator)
{
IEnumerable<Type> viewEngineTypes = ViewEngines.Select(ve => ve.GetType());
serviceLocator.GetAllInstances<IViewEngine>()
.Each(engine =>
{
if (!viewEngineTypes.Any(type => type == engine.GetType()))
{
ViewEngines.Add(engine);
}
});
}
示例6: ExecuteCore
/// <summary>
/// Executes the task.
/// </summary>
/// <param name="serviceLocator">The service locator.</param>
protected override void ExecuteCore(IServiceLocator serviceLocator)
{
serviceLocator.GetAllInstances<IModelBinder>()
.Select(binder => new
{
Binder = binder,
Types = binder.GetType()
.GetCustomAttributes(KnownTypes.BindingAttributeType, true)
.OfType<BindingTypesAttribute>()
.SelectMany(attribute => attribute.Types)
})
.Each(pair => pair.Types.Each(type =>
{
if (!Binders.ContainsKey(type))
{
Binders.Add(type, pair.Binder);
}
}));
}
示例7: NewProjectViewModel
public NewProjectViewModel(IEventAggregator eventAggregator, IServiceLocator serviceLocator)
{
_eventAggregator = eventAggregator;
_experimentTypes = serviceLocator.GetAllInstances<IExperimentType>();
_documentManager = serviceLocator.GetInstance<IDocumentManager>();
_recentLocations = Properties.Settings.Default.RecentLocations.Split(new char[] { ';' }, System.StringSplitOptions.RemoveEmptyEntries);
_selectedExperimentType = _experimentTypes.Where(type => type.Name == Properties.Settings.Default.LastSelectedExperimentType).FirstOrDefault();
_selectedExperimentType = _selectedExperimentType ?? _experimentTypes.First();
if (string.IsNullOrEmpty(Properties.Settings.Default.LastBrowseLocation))
{
string documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
Properties.Settings.Default.LastBrowseLocation = Path.Combine(documents, "Mass Spec Studio Projects");
}
_location = Properties.Settings.Default.LastBrowseLocation;
_projectName = GetNextDirectoryName(_location, _selectedExperimentType.Name + "Project");
_experimentName = _selectedExperimentType.Name + "Experiment";
}
示例8: Open
public static Experiment Open(string path, ProjectBase parentProject, IServiceLocator serviceLocator)
{
DataContractSerializer serializer = new DataContractSerializer(typeof(Experiment));
using (XmlReader stream = XmlReader.Create(path))
{
Experiment experiment = serializer.ReadObject(stream, true) as Experiment;
experiment.Project = parentProject;
if (parentProject == null)
{
string directory = Path.GetDirectoryName(path);
experiment.Peptides = Peptides.Open(Path.Combine(directory, experiment.PeptidesFileLocation));
}
else
{
experiment.Peptides = Peptides.Open(Path.Combine(experiment.Directory, experiment.PeptidesFileLocation));
}
if (parentProject != null)
{
experiment.Results = Result.OpenDirectory(experiment);
}
IDataProvider dataProvider = serviceLocator.GetAllInstances<IDataProvider>().Where(item => item.TypeId == experiment.DataProviderType).FirstOrDefault();
if (dataProvider == null)
{
throw new Exception("Data provider specified in this experiment was not found.");
}
experiment.DataProvider = dataProvider;
foreach (Run run in experiment.Runs)
{
run.Experiment = experiment;
}
return experiment;
}
}