static void ComponentContainerSetUp(object sender, ComponentEventArgs e) { // HACK: This reflection mess fixes SD2-1374 and SD2-1375. However I am not sure why it is needed in the first place. // There seems to be a problem with the nested container class used // by the designer. It only establishes a connection to the service // provider of the DesignerHost after it has been queried for // an IServiceContainer service. This does not always happen // automatically, so we enforce that here. We have to use // reflection because the request for IServiceContainer is // not forwarded by higher-level GetService methods. // Also, be very careful when trying to troubleshoot this using // the debugger because it automatically gets all properties and // this can cause side effects here, such as initializing that service // so that the problem no longer appears. INestedContainer nestedContainer = e.Component.Site.GetService(typeof(INestedContainer)) as INestedContainer; if (nestedContainer != null) { MethodInfo getServiceMethod = nestedContainer.GetType().GetMethod("GetService", BindingFlags.Instance | BindingFlags.NonPublic, null, new [] { typeof(Type) }, null); if (getServiceMethod != null) { LoggingService.Debug("Forms designer: Initializing nested service container of " + e.Component.ToString() + " using Reflection"); getServiceMethod.Invoke(nestedContainer, BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic, null, new [] { typeof(IServiceContainer) }, null); } } }
public ColumnExploration(ExplorationConfig config, INestedContainer scope, string column) { this.scope = scope; publisher = scope.GetInstance <MetricsPublisher>(); Column = column; Completion = Task.WhenAll(config.Tasks); }
public ExplorationScope Build(INestedContainer scope, ExplorerContext context) { var explorationScope = new ExplorationScope(scope); explorationScope.UseContext(context); Configure(explorationScope, context); return(explorationScope); }
public override void Initialize(IComponent component) { base.Initialize(component); this.host = (IDesignerHost)this.GetService(typeof(IDesignerHost)); if (((ToolStripKeyboardHandlingService)this.GetService(typeof(ToolStripKeyboardHandlingService))) == null) { ToolStripKeyboardHandlingService service = new ToolStripKeyboardHandlingService(component.Site); } if (((ISupportInSituService)this.GetService(typeof(ISupportInSituService))) == null) { ISupportInSituService service2 = new ToolStripInSituService(base.Component.Site); } this.dropDown = (ToolStripDropDown)base.Component; this.dropDown.Visible = false; this.AutoClose = this.dropDown.AutoClose; this.AllowDrop = this.dropDown.AllowDrop; this.selSvc = (ISelectionService)this.GetService(typeof(ISelectionService)); if (this.selSvc != null) { if ((this.host != null) && !this.host.Loading) { this.selSvc.SetSelectedComponents(new IComponent[] { this.host.RootComponent }, SelectionTypes.Replace); } this.selSvc.SelectionChanging += new EventHandler(this.OnSelectionChanging); this.selSvc.SelectionChanged += new EventHandler(this.OnSelectionChanged); } this.designMenu = new MenuStrip(); this.designMenu.Visible = false; this.designMenu.AutoSize = false; this.designMenu.Dock = DockStyle.Top; Control rootComponent = this.host.RootComponent as Control; if (rootComponent != null) { this.menuItem = new ToolStripMenuItem(); this.menuItem.BackColor = SystemColors.Window; this.menuItem.Name = base.Component.Site.Name; this.menuItem.Text = (this.dropDown != null) ? this.dropDown.GetType().Name : this.menuItem.Name; this.designMenu.Items.Add(this.menuItem); rootComponent.Controls.Add(this.designMenu); this.designMenu.SendToBack(); this.nestedContainer = this.GetService(typeof(INestedContainer)) as INestedContainer; if (this.nestedContainer != null) { this.nestedContainer.Add(this.menuItem, "ContextMenuStrip"); } } new EditorServiceContext(this, TypeDescriptor.GetProperties(base.Component)["Items"], System.Design.SR.GetString("ToolStripItemCollectionEditorVerb")); if (this.undoEngine == null) { this.undoEngine = this.GetService(typeof(UndoEngine)) as UndoEngine; if (this.undoEngine != null) { this.undoEngine.Undone += new EventHandler(this.OnUndone); } } }
public static void InjectDisposable <T>(this INestedContainer nc, T instance, bool replace = false) { if (replace && nc.GetInstance <T>() is IDisposable old) { old.Dispose(); } nc.Inject(instance, replace); ((Scope)nc).TryAddDisposable(instance); }
public static T ResolvePublisherComponent <T>(this INestedContainer scope) where T : PublisherComponent { // Try to resolve using the PublisherComponent interface. If this doesn't work, auto-resolve // the concrete instance instead. var fromCollection = (T)scope.TryGetInstance <PublisherComponent>(typeof(T).NameInCode()); return(fromCollection ?? scope.GetInstance <T>()); }
public Lamar_ScopePublish() { _container = new Container(registry => { registry.AddMassTransit(cfg => { cfg.AddBus(context => BusControl); }); }); _childContainer = _container.GetNestedContainer(); }
private void OnComponentAdding(object sender, ComponentEventArgs ce) { if ((this.addingComponent != null) && (this.addingComponent != ce.Component)) { this.inheritedComponents[ce.Component] = InheritanceAttribute.InheritedReadOnly; INestedContainer container = sender as INestedContainer; if ((container != null) && (container.Owner == this.addingComponent)) { this.inheritedComponents[ce.Component] = this.addingAttribute; } } }
public Lamar_ScopeRequestClient() { _container = new Container(registry => { registry.AddMassTransit(cfg => { cfg.AddRequestClient <SimpleMessageClass>(InputQueueAddress); cfg.AddRequestClient <PingMessage>(); cfg.AddBus(context => BusControl); }); }); _childContainer = _container.GetNestedContainer(); }
/// <summary> /// Configure a column exploration within a given scope. /// </summary> /// <param name="scope">The scoped container to use for object resolution.</param> /// <param name="conn">A DConnection configured for the Api backend.</param> /// <param name="ctx">An <see cref="ExplorerContext" /> defining the exploration parameters.</param> /// <param name="componentConfiguration"> /// An action to add and configure the components to use in this exploration. /// </param> /// <returns>A new ColumnExploration object.</returns> public static ColumnExploration ExploreColumn( INestedContainer scope, DConnection conn, ExplorerContext ctx, Action <ExplorationConfig> componentConfiguration) { // Configure a new Exploration var config = new ExplorationConfig(scope); config.UseConnection(conn); config.UseContext(ctx); config.Compose(componentConfiguration); return(new ColumnExploration(config, scope, ctx.Column)); }
public void NestedContainerTest() { Control control = (Control)_helper.CreateControl(typeof(TestButton), null); Control nestedControl = new TestButton(); // The following two tests show that the DT Site: // * offers the added site-specific services via IServiceProvider // * doesn't offer its implementation of IServiceContainer as a site-specific service // * GetService is routed through the owner // INestedContainer nestedContainer = control.Site.GetService(typeof(INestedContainer)) as INestedContainer; nestedContainer.Add(nestedControl); ((IServiceContainer)nestedControl.Site).AddService(typeof(DesignSurfaceTest), new DesignSurfaceTest()); Assert.IsNotNull(nestedControl.Site.GetService(typeof(DesignSurfaceTest)), "#1"); Assert.AreEqual(nestedControl.Site.GetService(typeof(IServiceContainer)), _helper.DesignSurface.GetService(typeof(IServiceContainer)), "#2"); Assert.IsNotNull(nestedControl.Site.GetService(typeof(DesignSurface)), "#3"); }
protected bool EnableDesignMode(Control child, string name) { if (name == null) { throw new ArgumentNullException("name"); } if (child == null) { throw new ArgumentNullException("child"); } bool success = false; INestedContainer nestedContainer = this.GetService(typeof(INestedContainer)) as INestedContainer; if (nestedContainer != null) { nestedContainer.Add(child, name); success = true; } return(success); }
private void DisposeMenu() { this.HideMenu(); Control rootComponent = this.host.RootComponent as Control; if (rootComponent != null) { if (this.designMenu != null) { rootComponent.Controls.Remove(this.designMenu); } if (this.menuItem != null) { if (this.nestedContainer != null) { this.nestedContainer.Dispose(); this.nestedContainer = null; } this.menuItem.Dispose(); this.menuItem = null; } } }
private void DisposeMenu() { this.HideMenu(); Control rootComponent = this.host.RootComponent as Control; if (rootComponent != null) { if (this.designMenu != null) { rootComponent.Controls.Remove(this.designMenu); } if (this.menuItem != null) { if (this.nestedContainer != null) { this.nestedContainer.Dispose(); this.nestedContainer = null; } this.menuItem.Dispose(); this.menuItem = null; } } }
public override void Initialize(IComponent component) { base.Initialize(component); this.host = (IDesignerHost) this.GetService(typeof(IDesignerHost)); if (((ToolStripKeyboardHandlingService) this.GetService(typeof(ToolStripKeyboardHandlingService))) == null) { ToolStripKeyboardHandlingService service = new ToolStripKeyboardHandlingService(component.Site); } if (((ISupportInSituService) this.GetService(typeof(ISupportInSituService))) == null) { ISupportInSituService service2 = new ToolStripInSituService(base.Component.Site); } this.dropDown = (ToolStripDropDown) base.Component; this.dropDown.Visible = false; this.AutoClose = this.dropDown.AutoClose; this.AllowDrop = this.dropDown.AllowDrop; this.selSvc = (ISelectionService) this.GetService(typeof(ISelectionService)); if (this.selSvc != null) { if ((this.host != null) && !this.host.Loading) { this.selSvc.SetSelectedComponents(new IComponent[] { this.host.RootComponent }, SelectionTypes.Replace); } this.selSvc.SelectionChanging += new EventHandler(this.OnSelectionChanging); this.selSvc.SelectionChanged += new EventHandler(this.OnSelectionChanged); } this.designMenu = new MenuStrip(); this.designMenu.Visible = false; this.designMenu.AutoSize = false; this.designMenu.Dock = DockStyle.Top; Control rootComponent = this.host.RootComponent as Control; if (rootComponent != null) { this.menuItem = new ToolStripMenuItem(); this.menuItem.BackColor = SystemColors.Window; this.menuItem.Name = base.Component.Site.Name; this.menuItem.Text = (this.dropDown != null) ? this.dropDown.GetType().Name : this.menuItem.Name; this.designMenu.Items.Add(this.menuItem); rootComponent.Controls.Add(this.designMenu); this.designMenu.SendToBack(); this.nestedContainer = this.GetService(typeof(INestedContainer)) as INestedContainer; if (this.nestedContainer != null) { this.nestedContainer.Add(this.menuItem, "ContextMenuStrip"); } } new EditorServiceContext(this, TypeDescriptor.GetProperties(base.Component)["Items"], System.Design.SR.GetString("ToolStripItemCollectionEditorVerb")); if (this.undoEngine == null) { this.undoEngine = this.GetService(typeof(UndoEngine)) as UndoEngine; if (this.undoEngine != null) { this.undoEngine.Undone += new EventHandler(this.OnUndone); } } }
public MessageHandlerScope(INestedContainer nestedContainer, Type handlerType) { _nestedNestedContainer = nestedContainer; Handler = (IMessageHandler)nestedContainer.GetInstance(handlerType); }
public ExplorationTestScope(Container rootContainer) { scopedContainer = rootContainer.GetNestedContainer(); }
public LamarNestedContainerAdapter(INestedContainer lamarContainer) { _lamarContainer = lamarContainer; }
public LamarDependencyScope(INestedContainer container) { this.container = container; }
public static void UpdatePayload(this PipeContext context, INestedContainer nestedContainer) { context.AddOrUpdatePayload(() => nestedContainer, existing => nestedContainer); }
public static void InjectDisposable <T>(this INestedContainer nc, T instance, bool replace = false) { nc.Inject(instance, replace); ((Scope)nc).TryAddDisposable(instance); }
public ExplorationConfig(INestedContainer scope) { this.scope = scope; }
public static void UpdateScope(this INestedContainer container, ConsumeContext consumeContext) { container.Inject(consumeContext); }
public ExplorationScope(INestedContainer scope) { this.scope = scope; logger = scope.GetInstance <ILogger <ExplorationScope> >(); }