private IHandler <T> GetHandler <T>(object handlerTypeOrInstance) { var instance = handlerTypeOrInstance as IHandler <T>; if (instance != null) { return(instance); } return((IHandler <T>)UnityService.Resolve((Type)handlerTypeOrInstance)); }
/// <summary> /// <see cref="System.ServiceModel.Dispatcher.IInstanceProvider"/> /// </summary> /// <param name="instanceContext"><see cref="System.ServiceModel.Dispatcher.IInstanceProvider"/></param> /// <param name="message"><see cref="System.ServiceModel.Dispatcher.IInstanceProvider"/></param> /// <returns><see cref="System.ServiceModel.Dispatcher.IInstanceProvider"/></returns> public object GetInstance(InstanceContext instanceContext, System.ServiceModel.Channels.Message message) { //This is the only call to UNITY container in the whole solution var parentInterface = _serviceType.GetInterfaces().FirstOrDefault(item => { var attrs = item.GetCustomAttributes(typeof(ServiceContractAttribute), false); return(attrs.Length > 0); }); return(UnityService.Resolve(parentInterface ?? _serviceType)); }
/// <summary> /// 调用示例 /// /// </summary> /// <typeparam name="TService"></typeparam> public static void AsyncExecuteServiceAction <TService>(this TService service, string actionName, params object[] parameters) where TService : CoralService { System.Threading.Tasks.Task.Factory.StartNew(() => { using (var newservice = UnityService.Resolve <TService>()) { newservice.InitContext(service.AppContext, service.UserContext, service.SessionContext, service.PageContext); newservice.ExecuteMethod <object>(actionName, parameters); } }); }
public void InstallModules() { try { _modules = MetaDataManager.Type.Find(CoralModule.IsCoralModule) .SortByDependencies(item => { //所有的模块都默认依赖于CoralModule if (item == typeof(CoreModule)) { return(new List <Type>()); } var dependencies = DependencyAttribute.GetDependencies(item).Where(type => !type.IsAbstract).ToList(); dependencies.Add(typeof(CoreModule)); return(dependencies); }) .Select(item => UnityService.Resolve(item) as CoralModule) .Where(item => item != null) .ToList(); _coralModules = new Dictionary <string, CoralModule>(); _typeModules = new Dictionary <Type, CoralModule>(); //构建名字和模块的字典 foreach (var module in _modules) { if (_coralModules.ContainsKey(module.Name)) { throw CoralException.ThrowException(item => item.ModuleExisted, module.Name); } _coralModules.Add(module.Name, module); } //构建类型 foreach (var module in _modules) { foreach (var type in module.Types) { if (!_typeModules.ContainsKey(type)) { _typeModules.Add(type, module); } } } _modules.ForEach(item => item.Prepare()); _modules.ForEach(item => item.Install()); _modules.ForEach(item => item.Installed()); } catch (ReflectionTypeLoadException ex) { throw new CoralModuleException(ex); } }
public GenericsFactory() { InitStrategys(); Creator = type => (TStrategy)UnityService.Resolve(type); }
public override void Install() { UnityService.Resolve <DbFactory>().Init(); }