public GraceDependencyInjectionContainer(IExportLocator container) { if (container == null) throw new ArgumentNullException("container"); this.container = container; }
/// <summary> /// Default Constructor /// </summary> /// <param name="conventionsService">conventions service</param> /// <param name="viewModelResolutionService">view model resolution service</param> /// <param name="locator">locator</param> public ConventionsViewBinder(IConventionsService conventionsService, IViewModelResolutionService viewModelResolutionService, IExportLocator locator) { this.conventionsService = conventionsService; this.viewModelResolutionService = viewModelResolutionService; this.locator = locator; }
public GraceDependencyInjectionContainer(IExportLocator container) { if (container == null) { throw new ArgumentNullException("container"); } this.container = container; }
/// <summary> /// Creates and Binds a viewmodel to a view /// </summary> /// <param name="injectionScope"></param> /// <param name="view">view to bind to</param> /// <param name="viewModelName">name of the view model to bind to</param> public bool ResolveViewModel(IExportLocator injectionScope, FrameworkElement view, string viewModelName) { bool foundModel = false; object viewModel = null; object oldViewModel = view.DataContext; if (!string.IsNullOrEmpty(viewModelName)) { try { IInjectionContext injectionContext = injectionScope.CreateContext(); IViewContext viewContext = new ViewContext(view); injectionContext.Export((s, c) => viewContext); viewModel = injectionScope.Locate(viewModelName, injectionContext); if (viewModel != null) { foundModel = true; Logger.Debug(string.Format("Resolved ViewModel Name {0} to Type {1}", viewModelName, viewModel.GetType().FullName)); } } catch (Exception exp) { Logger.Error("Exception thrown while creating ViewModel: " + viewModelName, SUPPLEMENTAL_STRING, exp); } } if (foundModel) { ProcessNewModel(view, viewModel); ProcessOldModel(view, oldViewModel); } return foundModel; }
/// <summary> /// Creates and Binds a viewmodel to a view /// </summary> /// <param name="injectionScope">injection scope to resolve from</param> /// <param name="view">view to bind to</param> /// <param name="viewModelType">type of the view model to bind to</param> public void ResolveViewModel(IExportLocator injectionScope, FrameworkElement view, Type viewModelType) { object viewModel = null; object oldViewModel = view.DataContext; if (viewModelType != null) { try { viewModel = injectionScope.Locate(viewModelType); if (viewModel == null) { Logger.Error("Could not locate exported ViewModel of type: " + viewModelType.FullName, SUPPLEMENTAL_STRING); } else { Logger.Debug(string.Format("Resolved ViewModel Type {0} to Type {1}", viewModelType.FullName, viewModel.GetType().FullName)); } } catch (Exception exp) { Logger.Error("Exception thrown while creating ViewModel: " + viewModelType.FullName, SUPPLEMENTAL_STRING, exp); } } ProcessNewModel(view, viewModel); ProcessOldModel(view, oldViewModel); }
public GraceInstanceProvider(IExportLocator exportLocator, Type serviceType) { this.exportLocator = exportLocator; this.serviceType = serviceType; }
protected GraceBaseServiceHostFactory(IExportLocator exportLocator) { this.exportLocator = exportLocator; }
public GraceWebServiceHostFactory(IExportLocator exportLocator) : base(exportLocator) { }
/// <summary> /// Default constructor /// </summary> /// <param name="container"></param> public ViewPageActivator(IExportLocator container) { _container = container; }
public GraceServiceBehavior(IExportLocator locator) { this.locator = locator; }
private static bool TestForSpecialType(IExportLocator locator, Type importType) { if (importType == typeof(IDisposalScope) || importType == typeof(IExportLocator) || importType == typeof(IInjectionScope) || importType == typeof(IDependencyInjectionContainer)) { return true; } if (importType.IsConstructedGenericType) { Type openType = importType.GetGenericTypeDefinition(); if (TestForListSpecialType(openType)) { return true; } if (importType.FullName.StartsWith("System.Func`")) { return true; } if (TestForLazyType(openType)) { return true; } if (TestForOwnedType(openType)) { return true; } } if (importType.IsArray) { return true; } return false; }
private static bool LocateExportByType(IExportLocator locator, ExportStrategyDependency exportStrategyDependency) { if (locator.GetStrategy(exportStrategyDependency.ImportType) != null) { return true; } if (TestForSpecialType(locator, exportStrategyDependency.ImportType)) { return true; } if (exportStrategyDependency.ImportType.GetTypeInfo().IsClass && !exportStrategyDependency.ImportType.GetTypeInfo().IsAbstract && !exportStrategyDependency.ImportType.GetTypeInfo().IsInterface) { return true; } IInjectionScope injectionScope = locator as IInjectionScope; if (injectionScope != null) { InjectionContext context = new InjectionContext(injectionScope); foreach (ISecondaryExportLocator secondaryExportLocator in injectionScope.SecondaryExportLocators) { if (secondaryExportLocator.CanLocate(context, null, exportStrategyDependency.ImportType, null, null)) { return true; } } if (injectionScope.ParentScope != null) { return LocateExportByType(injectionScope.ParentScope, exportStrategyDependency); } } return false; }
/// <summary> /// Calculates a list of possible missing dependencies /// </summary> /// <param name="locator"></param> /// <returns></returns> public static IEnumerable<PossibleMissingDependency> CalculatePossibleMissingDependencies(IExportLocator locator) { List<PossibleMissingDependency> possibleMissingDependencies = new List<PossibleMissingDependency>(); foreach (IExportStrategy exportStrategy in locator.GetAllStrategies()) { foreach (ExportStrategyDependency exportStrategyDependency in exportStrategy.DependsOn) { if (exportStrategyDependency.HasValueProvider) { continue; } if (exportStrategyDependency.ImportName != null) { } else if (exportStrategyDependency.ImportType != null && LocateExportByType(locator, exportStrategyDependency)) { continue; } possibleMissingDependencies.Add(new PossibleMissingDependency { Dependency = exportStrategyDependency, Strategy = exportStrategy }); } } possibleMissingDependencies.Sort((x, y) => string.CompareOrdinal(x.Dependency.DebuggerDisplayString, y.Dependency.DebuggerDisplayString)); return possibleMissingDependencies; }
public GraceDependencyResolver(IExportLocator container) { this.container = container; }
/// <summary> /// Sets the design time locator /// </summary> /// <param name="obj"></param> /// <param name="value"></param> public static void SetDesignTimeExportLocator(DependencyObject obj, IExportLocator value) { obj.SetValue(DesignTimeExportLocatorProperty, value); }