public InterfaceT Resolve <InterfaceT>(string alias, string resolverName = "") { int resultError; InterfaceT result = default; IResolvable resolvable = ServersHolder.GetResolvable(ref alias, out resultError); if (resultError == 0) { IResolverHandler resolverHandler = resolvable.GetResolver <InterfaceT>(Resolvable.RESOLVER_DEF, out _); resolverHandler.InvokeResolver(); result = (InterfaceT)resolverHandler.ResolverParam; resolverHandler = resolvable.GetResolver <InterfaceT>(Resolvable.RESOLVER_CRT, out _); resolverHandler.SetParam(ref result); resolverHandler.InvokeResolver(); result = (InterfaceT)resolverHandler.ResolverParam; if ((result != default) && !string.IsNullOrEmpty(resolverName)) { resolverHandler = resolvable.GetResolver <InterfaceT>(resolverName, out _); resolverHandler.SetParam(ref result); resolverHandler.InvokeResolver(); if (resolverHandler.OnlyOnce) { resolvable.RemoveResolver <InterfaceT>(resolverName, out _); } } } return(result); }
/// <summary> /// 通过接口及别名解析出一个对象的实例并根据解析器名调用解析器函数 /// </summary> /// <typeparam name="InterfaceT">接口</typeparam> /// <param name="alias">别名</param> /// <param name="resolverName">解析器名,用于将解析得到的对象传入对应的加工函数,不传此参表示仅获取实例</param> /// <param name="customResolver">定制的解析器函数,在传入加工函数前预处理解析得到的对象</param> /// <returns>需要获得的实例对象</returns> public InterfaceT Resolve <InterfaceT>(string alias, string resolverName = "", ResolveDelegate <InterfaceT> customResolver = default) { int resultError; InterfaceT result = default; IResolvable resolvable = ServersHolder.GetResolvable(ref alias, out resultError); "error:Resolvable is null, alias is {0}".Log(resolvable == default, alias); if (resultError == 0) { IResolverHandler resolverHandler; resolverHandler = resolvable.GetResolver <InterfaceT>(Resolvable.RESOLVER_CRT, out _); resolverHandler.InvokeResolver(); result = (InterfaceT)resolverHandler.ResolverParam; resolverHandler = resolvable.GetResolver <InterfaceT>(Resolvable.RESOLVER_INIT, out _); resolverHandler.SetParam(ref result); resolverHandler.InvokeResolver(); result = (InterfaceT)resolverHandler.ResolverParam; if (!result.Equals(default))
/// <summary> /// 重新注册解析器的解析器函数,并返回旧的解析器函数 /// </summary> public ResolveDelegate <InterfaceT> Reregister <InterfaceT>(ResolveDelegate <InterfaceT> target, string alias) { ResolveDelegate <InterfaceT> raw = default; IResolvable resolvable = ServersHolder.GetResolvable(ref alias, out int resultError); if (resultError == 0) { IResolverCacher <InterfaceT> resolverHandler = resolvable.GetResolver <InterfaceT>(Resolvable.RESOLVER_INIT, out _) as IResolverCacher <InterfaceT>; raw = resolverHandler.DelegateTarget; resolverHandler.SetDelegate(target); } return(raw); }