internal IStObjServiceFinalManualMapping CreateServiceFinalManualMapping(IStObjServiceClassFactoryInfo c) { Debug.Assert(_serviceManualList.IndexOf(x => x.ClassType == c.ClassType) < 0, "Unique registration check must be done by the caller."); var r = new StObjServiceFinalManualMapping(_serviceManualList.Count, c); _serviceManualList.Add(r); return(r); }
static object Create(IServiceProvider provider, IStObjServiceClassFactoryInfo c, Dictionary <IStObjServiceClassFactoryInfo, object> cache) { if (!cache.TryGetValue(c, out var result)) { var ctor = c.GetSingleConstructor(); var parameters = ctor.GetParameters(); var values = new object?[parameters.Length]; for (int i = 0; i < parameters.Length; ++i) { var p = parameters[i]; var mapped = c.Assignments.Where(a => a.Position == p.Position).FirstOrDefault(); if (mapped == null) { values[i] = provider.GetService(p.ParameterType); } else { if (mapped.Value == null) { values[i] = null; } else if (mapped.IsEnumerated) { values[i] = mapped.Value.Select(v => provider.GetService(v)).ToArray(); } else { values[i] = provider.GetService(mapped.Value[0]); } } } result = ctor.Invoke(values); cache.Add(c, result); } return(result); }
public StObjServiceFinalManualMapping(int number, IStObjServiceClassFactoryInfo c) { ManualMappingIndex = number; _c = c; }
/// <summary> /// Gets the single constructor information of the type. /// Currently, there must be one and only one public constructor. /// If it happens that other public constructors are needed, this function /// will filter the constructor to use with an attribute, however for the moment, /// it returns the linq Single() one. /// </summary> /// <param name="this">This service class factory info.</param> /// <returns>The single constructor to consider.</returns> public static ConstructorInfo GetSingleConstructor(this IStObjServiceClassFactoryInfo @this) { return(@this.ClassType.GetConstructors().Single()); }