/// <summary> /// 从容器中解析指定类型 /// </summary> public object Resolve(Type type) { Activator activator; if (!_cache.TryGet(type, out activator)) { throw new XFrameworkException(type.FullName + " is not registered"); } if (activator.Instance != null) { return(activator.Instance); } Func <object> func = activator.Builder; if (func == null) { XFrameworkException.Throw(type.FullName + " is not registered"); } return(func()); }
/// <summary> /// 从容器中解析指定类型 /// </summary> public T Resolve <T>() where T : class { Activator activator; if (!_cache.TryGet(typeof(T), out activator)) { throw new XFrameworkException(typeof(T).FullName + " is not registered"); } if (activator.Instance != null) { return((T)activator.Instance); } Func <object> func = activator.Builder; if (func == null) { XFrameworkException.Throw(typeof(T).FullName + " is not registered"); } return((T)func()); }