public object Resolve(Type type, object parameter) { if (type == null) { throw new ArgumentNullException("type"); } var args = new ServiceResolvingEventArgs(type, parameter, false); //激发“Resolving”事件 this.OnResolving(args); if (args.Cancel) { return(args.Result); } object result = null; var entry = _storage.Get(type, parameter); if (entry != null) { result = this.GetService(entry); } //激发“Resolved”事件 this.OnResolved(new ServiceResolvedEventArgs(type, parameter, false, result)); //返回解析的结果 return(result); }
public IEnumerable <object> ResolveAll(Type type, object parameter) { if (type == null) { throw new ArgumentNullException("type"); } var args = new ServiceResolvingEventArgs(type, parameter, true); //激发“Resolving”事件 this.OnResolving(args); if (args.Cancel) { return(args.Result as IEnumerable <object>); } IEnumerable <object> result; var entries = _storage.GetAll(type, parameter); if (entries == null) { result = Enumerable.Empty <object>(); } else { result = entries.Select(entry => this.GetService(entry)); } //激发“Resolved”事件 this.OnResolved(new ServiceResolvedEventArgs(type, parameter, true, result)); //返回结果集 return(result); }
public object Resolve(string name) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException("name"); } var args = new ServiceResolvingEventArgs(name); //激发“Resolving”事件 this.OnResolving(args); if (args.Cancel) { return(args.Result); } object result = null; var entry = _storage.Get(name); if (entry != null) { result = this.GetService(entry); } //激发“Resolved”事件 this.OnResolved(new ServiceResolvedEventArgs(name, result)); //返回解析的结果 return(result); }
protected virtual void OnResolving(ServiceResolvingEventArgs args) { var resolving = this.Resolving; if (resolving != null) { resolving(this, args); } }