/// <summary> /// Registers an expected DI entry with the configuration. If the type is incorrect, or does not exist, an exception is thrown. /// </summary> protected virtual void RegisterExpectedConfigType <TResultType>(XmlElement configuration, XmlElement defaults, string elementName, IConfiguration registry) where TResultType : class { var type = GetConfigType(configuration, defaults, elementName); var attributes = GetUnmappedAttributes(configuration, defaults, elementName); var resultType = typeof(TResultType); if (resultType == typeof(ISourceDataStore)) { Func <IDataStore> factory = () => (IDataStore)registry.Activate(type.Type, attributes); Func <object> wrapperFactory = () => new ConfigurationDataStore(new Lazy <IDataStore>(factory)); registry.Register(resultType, wrapperFactory, type.SingleInstance); return; } if (resultType == typeof(ITargetDataStore)) { Func <IDataStore> factory = () => (IDataStore)registry.Activate(type.Type, attributes); Func <object> wrapperFactory = () => new ConfigurationDataStore(new Lazy <IDataStore>(factory)); registry.Register(resultType, wrapperFactory, type.SingleInstance); return; } if (!resultType.IsAssignableFrom(type.Type)) { throw new InvalidOperationException("Invalid type for Unicorn config node '{0}' (expected '{1}' implementation)".FormatWith(elementName, typeof(TResultType).FullName)); } RegisterGenericConfigTypeByInterfaces(configuration, defaults, elementName, registry); }
public void CreateConfiguration() { Host.IApplication application = HostApplicationSelector.SelectedApplication; IConfiguration configuration = application.Configurations.Create(ConfigurationSettings); if (StartProfilingImmediately) { configuration.Activate(); } TryClose(true); }
/// <summary> /// Registers an ad-hoc DI entry with the configuration, using its interfaces as the registrations /// </summary> protected virtual void RegisterGenericConfigTypeByInterfaces(XmlElement configuration, XmlElement defaults, string elementName, IConfiguration registry) { var type = GetConfigType(configuration, defaults, elementName); var interfaces = type.Type.GetInterfaces(); var attributes = GetUnmappedAttributes(configuration, defaults, elementName); foreach (var @interface in interfaces) { registry.Register(@interface, () => registry.Activate(type.Type, attributes), type.SingleInstance); } }
public object Activate(Type type, KeyValuePair <string, object>[] unmappedConstructorParameters) { return(_innerConfiguration.Activate(type, unmappedConstructorParameters)); }