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; }
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; }); }
public void Inject <T>(T instance) where T : class => DependencyActivator.Activate(instance, this);