public TypeRegistration(Type typeFrom, Type typeTo, string name, LifetimeManager lifetimeManager, InjectionMember[] injectionMembers) { Name = string.IsNullOrEmpty(name) ? null : name; RegisteredType = typeFrom ?? typeTo; MappedToType = typeTo; LifetimeManager = lifetimeManager ?? TransientLifetimeManager; if (LifetimeManager.InUse) { throw new InvalidOperationException(Constants.LifetimeManagerInUse); } LifetimeManager.InUse = true; if (typeFrom != null && typeFrom != typeTo) { if (typeFrom.GetTypeInfo().IsGenericTypeDefinition&& typeTo.GetTypeInfo().IsGenericTypeDefinition) { this[typeof(IBuildKeyMappingPolicy)] = new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(typeTo, name)); } else { var policy = (null != injectionMembers && injectionMembers.Length > 0) || lifetimeManager is IRequireBuildUpPolicy ? new BuildKeyMappingPolicy(new NamedTypeBuildKey(typeTo, name)) : new ResolveMappingPolicy(new NamedTypeBuildKey(typeTo, name)); this[typeof(IBuildKeyMappingPolicy)] = policy; } } }
public void PolicyThrowsIfWrongNumberOfGenericParameters() { var original = new NamedTypeBuildKey(typeof(IList <string>)); IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(typeof(Dictionary <,>))); policy.Map(original, null); }
public void CanMapGenericTypeFromNamedTypeBuildKey() { NamedTypeBuildKey original = new NamedTypeBuildKey(typeof (IList<string>), "test"); IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(typeof (List<>), "test")); NamedTypeBuildKey result = policy.Map(original, null); Assert.AreEqual(typeof (List<string>), result.Type); Assert.AreEqual(original.Name, result.Name); }
public void CanMapGenericTypeToNewGenericType() { var original = new NamedTypeBuildKey(typeof (IList<int>)); var expected = new NamedTypeBuildKey(typeof (List<int>)); IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(typeof (List<>))); var result = policy.Map(original, null); Assert.AreEqual(expected, result); }
public void CanMapGenericTypeFromNamedTypeBuildKey() { NamedTypeBuildKey original = new NamedTypeBuildKey(typeof(IList <string>), "test"); IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(typeof(List <>), "test")); NamedTypeBuildKey result = policy.Map(original, null); Assert.Equal(typeof(List <string>), result.Type); Assert.Equal(original.Name, result.Name); }
public void CanMapGenericTypeToNewGenericType() { var original = new NamedTypeBuildKey(typeof(IList <int>)); var expected = new NamedTypeBuildKey(typeof(List <int>)); IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(typeof(List <>))); var result = policy.Map(original, null); Assert.Equal(expected, result); }
public void CanMapGenericTypeToNewGenericType() { Type original = typeof(IList <int>); Type expected = typeof(List <int>); IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(typeof(List <>)); Type result = (Type)policy.Map(original); Assert.AreEqual(expected, result); }
public void PolicyThrowsIfInputIsNotAGeneric() { IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(typeof(List <>))); try { policy.Map(new NamedTypeBuildKey <int>(), null); Assert.True(false, string.Format("Expected Exception")); } catch (ArgumentException) { // expected } }
public void PolicyThrowsIfWrongNumberOfGenericParameters() { var original = new NamedTypeBuildKey(typeof(IList<string>)); IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(typeof(Dictionary<,>))); try { policy.Map(original, null); Assert.Fail("Expected exception"); } catch (ArgumentException) { // expected } }
public void PolicyThrowsIfInputIsNotAGeneric() { IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(typeof(List<>))); try { policy.Map(new NamedTypeBuildKey<int>(), null); Assert.Fail("Expected Exception"); } catch (ArgumentException) { // expected } }
public void PolicyThrowsIfWrongNumberOfGenericParameters() { var original = new NamedTypeBuildKey(typeof(IList <string>)); IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(typeof(Dictionary <,>))); try { policy.Map(original, null); Assert.True(false, string.Format("Expected exception")); } catch (ArgumentException) { // expected } }
public void PolicyThrowsIfInputIsNotAGeneric() { IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(typeof (List<>))); policy.Map(new NamedTypeBuildKey<int>(), null); }
public void PolicyThrowsIfWrongNumberOfGenericParameters() { var original = new NamedTypeBuildKey(typeof (IList<string>)); IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(typeof (Dictionary<,>))); policy.Map(original, null); }
public void PolicyThrowsIfInputIsNotAGeneric() { IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(typeof(List <>))); policy.Map(new NamedTypeBuildKey <int>(), null); }
public void PolicyThrowsIfInputIsNotAGeneric() { IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(typeof(List <>))); Assert.Throws <ArgumentException>(() => policy.Map(new NamedTypeBuildKey <int>(), null)); }
public void PolicyThrowsIfInputIsNotAGeneric() { IBuildKeyMappingPolicy policy = new GenericTypeBuildKeyMappingPolicy(typeof(List <>)); policy.Map(typeof(int)); }