Exemplo n.º 1
0
        private static DependencyActivator getActivator(Type type)
        {
            if (!activator_cache.TryGetValue(type, out var existing))
            {
                return(activator_cache[type] = new DependencyActivator(type));
            }

            return(existing);
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        public CachedModelDependencyContainer(IReadOnlyDependencyContainer parent)
        {
            this.parent = parent;

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

            TModel currentModel = null;

            Model.BindValueChanged(e =>
            {
                // 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
                var newModel = e.NewValue ?? new TModel();

                updateShadowModel(shadowModel, currentModel, newModel);

                currentModel = newModel;
            });
        }
Exemplo n.º 4
0
 public void Inject <T>(T instance) where T : class => DependencyActivator.Activate(instance, this);