/// <summary> /// Adds or updates a generic definition in the repository. /// </summary> /// <param name="typeKey">The key type.</param> /// <param name="registration">The registration.</param> /// <param name="nameKey">The name of the registration.</param> public void AddOrUpdateGenericDefinition(Type typeKey, IServiceRegistration registration, string nameKey) { var immutableTree = ImmutableTree<IServiceRegistration>.Empty; var newTree = immutableTree.AddOrUpdate(nameKey.GetHashCode(), registration); lock (this.syncObject) { this.genericDefinitionRepository = this.genericDefinitionRepository.AddOrUpdate(typeKey.GetHashCode(), newTree, (oldValue, newValue) => newValue); } }
public void ApplyShouldWorkOnSelectedPropertyOfImmutableState() { ImmutableTree state = new ImmutableTree(1, false); ReducerComposer <ImmutableTree> composer = new ReducerComposer <ImmutableTree>(); composer.AddSubTreeReducer(new ImmutableIntPropReducer()) .AddSubTreeReducer(new ImmutableBoolPropReducer()); state = composer.Apply(state, ""); Assert.AreEqual(2, state.IntProp); Assert.AreEqual(true, state.BoolProp); }
public void ApplyShouldWorkOnSelectedPropertyOfImmutableState() { ImmutableTree state = new ImmutableTree(1, false); SubTreeToFullTreeAdapter <ImmutableTree, int> adapter1 = new SubTreeToFullTreeAdapter <ImmutableTree, int>(new ImmutableIntPropReducer()); SubTreeToFullTreeAdapter <ImmutableTree, bool> adapter2 = new SubTreeToFullTreeAdapter <ImmutableTree, bool>(new ImmutableBoolPropReducer()); state = adapter1.Apply(state, ""); state = adapter2.Apply(state, ""); Assert.AreEqual(2, state.IntProp); Assert.AreEqual(true, state.BoolProp); }
public static bool ContainsRegistration(this ImmutableTree <Type, ImmutableBucket <object, ServiceRegistration> > repository, Type type, object name) { var registrations = repository.GetOrDefaultByRef(type); if (name != null && registrations != null) { return(registrations.GetOrDefaultByValue(name) != null); } if (registrations != null || !type.IsClosedGenericType()) { return(registrations != null); } registrations = repository.GetOrDefaultByRef(type.GetGenericTypeDefinition()); return(registrations?.Any(reg => type.SatisfiesGenericConstraintsOf(reg.ImplementationTypeInfo)) ?? false); }
private bool TryGetRegistrationsByTypeWithoutGenericDefinitionExtraction(Type type, out ImmutableTree<IServiceRegistration> registrations) { registrations = this.serviceRepository.GetValueOrDefault(type.GetHashCode()); return registrations != null; }
private bool TryGetRegistrationsByType(Type type, out ImmutableTree<IServiceRegistration> registrations) { registrations = this.serviceRepository.GetValueOrDefault(type.GetHashCode()); if (registrations != null) return true; Type genericTypeDefinition; if (this.TryHandleOpenGenericType(type, out genericTypeDefinition)) { registrations = this.genericDefinitionRepository.GetValueOrDefault(genericTypeDefinition.GetHashCode()); } else { return false; } return registrations != null; }
/// <summary> /// Constructs a <see cref="RegistrationRepository"/> /// </summary> public RegistrationRepository() { this.serviceRepository = ImmutableTree<ImmutableTree<IServiceRegistration>>.Empty; this.genericDefinitionRepository = ImmutableTree<ImmutableTree<IServiceRegistration>>.Empty; }
/// <summary> /// Cleans up the repository. /// </summary> public void CleanUp() { foreach (var registration in this.serviceRepository.Enumerate().Select(reg => reg.Value).SelectMany(registrations => registrations.Enumerate())) { registration.Value.CleanUp(); } this.serviceRepository = null; }