private static DependencyActivator getActivator(Type type)
 {
     if (!activator_cache.TryGetValue(type, out var existing))
     {
         return(activator_cache[type] = new DependencyActivator(type));
     }
     return(existing);
 }
        private DependencyActivator(Type type)
        {
            injectionActivators.Add(ResolvedAttribute.CreateActivator(type));
            injectionActivators.Add(BackgroundDependencyLoaderAttribute.CreateActivator(type));
            buildCacheActivators.Add(CachedAttribute.CreateActivator(type));

            if (type.BaseType != typeof(object))
            {
                baseActivator = getActivator(type.BaseType);
            }

            activator_cache[type] = this;
        }
Ejemplo n.º 3
0
        public CachedModelDependencyContainer(IReadOnlyDependencyContainer parent)
        {
            this.parent = parent;

            shadowDependencies = DependencyActivator.MergeDependencies(shadowModel, null, new CacheInfo(parent: typeof(TModel)));

            Model.BindValueChanged(newModel =>
            {
                // When setting a null model, we actually want to reset the shadow model to a default state
                // rather than leaving the current state on-going
                newModel = newModel ?? new TModel();

                updateShadowModel(shadowModel, currentModel, newModel);

                currentModel = newModel;
            });
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Injects dependencies into the given instance.
 /// </summary>
 /// <typeparam name="T">The type of the instance to inject dependencies into.</typeparam>
 /// <param name="instance">The instance to inject dependencies into.</param>
 /// <exception cref="OperationCanceledException">When the injection process was cancelled.</exception>
 public void Inject <T>(T instance)
     where T : class
 => DependencyActivator.Activate(instance, this);