public void CanInjectExistingObject() { ExistingObject obj = new ExistingObject(); DependencyContainer container = new DependencyContainer(); container.RegisterSingletonInstance("Hello world"); container.Inject(obj); Assert.Equal("Hello world", obj.Name); }
public SdkInfoWindow(string[] SdkInfoEntries, Dictionary <string, string> Variables, Font BadgeFont) { InitializeComponent(); this.BadgeFont = BadgeFont; Dictionary <string, ConfigObject> UniqueIdToObject = new Dictionary <string, ConfigObject>(StringComparer.InvariantCultureIgnoreCase); foreach (string SdkInfoEntry in SdkInfoEntries) { ConfigObject Object = new ConfigObject(SdkInfoEntry); string UniqueId = Object.GetValue("UniqueId", Guid.NewGuid().ToString()); ConfigObject ExistingObject; if (UniqueIdToObject.TryGetValue(UniqueId, out ExistingObject)) { ExistingObject.AddOverrides(Object, null); } else { UniqueIdToObject.Add(UniqueId, Object); } } List <SdkItem> Items = new List <SdkItem>(); foreach (ConfigObject Object in UniqueIdToObject.Values) { SdkItem Item = new SdkItem(); Item.Category = Object.GetValue("Category", "Other"); Item.Description = Object.GetValue("Description", ""); Item.Install = Utility.ExpandVariables(Object.GetValue("Install", ""), Variables); if (Item.Install.Contains("$(")) { Item.Install = null; } Item.Browse = Utility.ExpandVariables(Object.GetValue("Browse", ""), Variables); if (Item.Browse.Contains("$(")) { Item.Browse = null; } if (!String.IsNullOrEmpty(Item.Install) && String.IsNullOrEmpty(Item.Browse)) { try { Item.Browse = Path.GetDirectoryName(Item.Install); } catch { Item.Browse = null; } } Items.Add(Item); } foreach (IGrouping <string, SdkItem> ItemGroup in Items.GroupBy(x => x.Category).OrderBy(x => x.Key)) { ListViewGroup Group = new ListViewGroup(ItemGroup.Key); SdkListView.Groups.Add(Group); foreach (SdkItem Item in ItemGroup) { ListViewItem NewItem = new ListViewItem(Group); NewItem.SubItems.Add(Item.Description); NewItem.SubItems.Add(new ListViewItem.ListViewSubItem() { Tag = Item }); SdkListView.Items.Add(NewItem); } } System.Reflection.PropertyInfo DoubleBufferedProperty = typeof(Control).GetProperty("DoubleBuffered", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); DoubleBufferedProperty.SetValue(SdkListView, true, null); if (SdkListView.Items.Count > 0) { int ItemsHeight = SdkListView.Items[SdkListView.Items.Count - 1].Bounds.Bottom + 20; Height = SdkListView.Top + ItemsHeight + (Height - SdkListView.Bottom); } }