internal ServiceContext(Type serviceType, FuncContext func) : this(serviceType) { if (func == null) { throw new ArgumentNullException("func"); } objectList.Add(new ObjectContext(func)); }
internal ObjectContext(FuncContext func) { if (func == null) { throw new ArgumentNullException("func"); } this.Func = func; this.Mode = CreateMode.Method; }
/// <summary> /// 注册TService Create func /// </summary> /// <typeparam name="TService">TService Type</typeparam> /// <param name="func">func</param> /// <returns>IRegisterContext</returns> public IRegisterContext Register <TService>(Func <IContainer, TService> func) { if (func == null) { throw new ArgumentNullException("func"); } var serviceType = typeof(TService); var funcContext = new FuncContext(func.Target, func.Method); ServiceContext serviceContext = this.GetOrAddServiceContext(serviceType); ObjectContext objectContext = serviceContext.Add(funcContext); return(new RegisterContext() { Container = this, ServiceType = serviceType, Context = objectContext }); }
public ObjectContext Add(FuncContext func) { if (func == null) { throw new ArgumentNullException("func"); } ObjectContext objectContext = null; lock (this.root) { objectContext = this.objectList.Find(q => q.Mode == CreateMode.Method && q.Func.Method == func.Method && (q.Func.Target == func.Target || q.Func.Target.Equals(func.Target))); if (objectContext == null) { objectContext = new ObjectContext(func); this.objectList.Add(objectContext); this.objectList.TrimExcess(); } } return(objectContext); }