/// <summary> /// Override of <see cref="IBuilderStrategy.BuildUp"/>. Creates the requested object using the custom factory associated to type <paramref name="t"/>. /// </summary> /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param> /// <param name="t">The type to build.</param> /// <param name="existing">The existing object. Should be <see langword="null"/>.</param> /// <param name="id">The ID of the object to be created.</param> /// <returns>The created object.</returns> /// <exception cref="InvalidOperationException"> when the requested type does not have the /// required <see cref="CustomFactoryAttribute">CustomFactory</see> attribute.</exception> /// <exception cref="System.Configuration.ConfigurationErrorsException"> when the configuration for the requested ID is not present or is /// invalid in the configuration source.</exception> public override object BuildUp(IBuilderContext context, Type t, object existing, string id) { string newId = id; IConfigurationSource configurationSource = GetConfigurationSource(context); ConfigurationReflectionCache reflectionCache = GetReflectionCache(context); ICustomFactory factory = GetCustomFactory(t, reflectionCache); if (factory != null) { existing = factory.CreateObject(context, newId, configurationSource, reflectionCache); } else { throw new InvalidOperationException( string.Format( Resources.Culture, Resources.ExceptionCustomFactoryAttributeNotFound, t.FullName, id)); } return(base.BuildUp(context, t, existing, newId)); }
private static void ProcessCustomFactory( ICustomFactory factory, object target, Dictionary <string, object> values, bool replace, string identifier, ref bool loaded) { foreach (var component in factory.Create(target, values)) { loaded = true; if (component == null) { continue; } Control.LogDebug(DType.CCLoading, $"Created {component} for {identifier}"); if (Database.SetCustomWithIdentifier(identifier, component, replace)) { if (component is IAfterLoad load) { Control.LogDebug(DType.CCLoading, $"IAfterLoad: {identifier}"); load.OnLoaded(values); } if (component is IAdjustDescription ed) { ed.AdjustDescription(); } } } }
public MockFactoryStrategy(ICustomFactory factory, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { this.factory = factory; this.configurationSource = configurationSource; this.reflectionCache = reflectionCache; }
public void CanGetNullCustomFactoryForNonAnnotatedTypeTheFirstTime() { MockImplementor.constructorCalls = 0; ICustomFactory factory = cache.GetCustomFactory(typeof(TypeWithNoCustomFactoryAttribute)); Assert.IsNull(factory); Assert.AreEqual(0, MockImplementor.constructorCalls); }
public ViaFileInfo(ICustomFactory factory) { if (factory == null) { throw new ArgumentNullException(nameof(factory)); } _factory = factory; }
public void CanGetCustomFactoryForAnnotatedTypeTheFirstTime() { MockImplementor.constructorCalls = 0; ICustomFactory factory = cache.GetCustomFactory(typeof(TypeWithCustomFactoryAttribute)); Assert.IsNotNull(factory); Assert.AreSame(typeof(MockImplementor), factory.GetType()); Assert.AreEqual(1, MockImplementor.constructorCalls); }
public ViaFile(IFile file, ICustomFactory factory) { if (file == null) { throw new ArgumentNullException(nameof(file)); } if (factory == null) { throw new ArgumentNullException(nameof(factory)); } _file = file; _factory = factory; }
public override void PreBuildUp(IBuilderContext context) { base.PreBuildUp(context); IConfigurationSource configurationSource = GetConfigurationSource(context); ConfigurationReflectionCache reflectionCache = GetReflectionCache(context); NamedTypeBuildKey key = (NamedTypeBuildKey)context.BuildKey; string id = key.Name; Type t = key.Type; ICustomFactory factory = GetCustomFactory(t, reflectionCache); if (factory != null) { context.Existing = factory.CreateObject(context, id, configurationSource, reflectionCache); } else { throw new InvalidOperationException( string.Format( Resources.Culture, Resources.ExceptionCustomFactoryAttributeNotFound, t.FullName, id)); } }
public FactoryUnityExtension(ICustomFactory factory) { this.factory = factory; }
public CustomFactoryBuildStrategy(ICustomFactory factory, ExtensionContext baseContext) { this.factory = factory; this.baseContext = baseContext; }
public ViaFileInfo(ICustomFactory factory) { _factory = factory ?? throw new ArgumentNullException(nameof(factory)); }
public ViaFile([NotNull] IFile file, [NotNull] ICustomFactory factory) { _file = file ?? throw new ArgumentNullException(nameof(file)); _factory = factory ?? throw new ArgumentNullException(nameof(factory)); }
private ICustomFactory GetCustomFactory(Type t, ConfigurationReflectionCache reflectionCache) { ICustomFactory customFactory = reflectionCache.GetCustomFactory(t); return(customFactory); }
public static void RegisterFactory(ICustomFactory factory) { Factories.Add(factory); }