Ejemplo n.º 1
0
        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();
                    }
                }
            }
        }
Ejemplo n.º 2
0
    public override void PreBuildUp(IBuilderContext context)
    {
        var key = (NamedTypeBuildKey)context.OriginalBuildKey;

        if (factory.CanCreate(key.Type) && context.Existing == null)
        {
            context.Existing = factory.Create(key.Type);
            var ltm = new ContainerControlledLifetimeManager();
            ltm.SetValue(context.Existing);
            // Find the container to add this to
            IPolicyList parentPolicies;
            var         parentMarker = context.Policies.Get <ParentMarkerPolicy>(new NamedTypeBuildKey <ParentMarkerPolicy>(), out parentPolicies);
            // TODO: add error check - if policy is missing, extension is misconfigured
            // Add lifetime manager to container
            parentPolicies.Set <ILifetimePolicy>(ltm, new NamedTypeBuildKey(key.Type));
            // And add to LifetimeContainer so it gets disposed
            parentMarker.AddToLifetime(ltm);
            // Short circuit the rest of the chain, object's already created
            context.BuildComplete = true;
        }
    }