public void DiscoverServices(IServicePool pool) { var registration = new RegistrationBuilder(); registration.ForTypesDerivedFrom<IService>().SelectConstructor((ConstructorInfo[] cInfo) => { if (cInfo.Length == 0) return null; return cInfo[0]; }).Export<IService>(); var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var catalog = new DirectoryCatalog(path, registration); var container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); var services = container.GetExportedValues<IService>(); foreach (var service in services) { service.ServicePool = pool; var interfaces = service.GetType().GetInterfaces(); Type interfaceType = null; foreach (var i in interfaces) { var name = i.FullName; if (!name.Contains("Contracts.IService") && !name.Contains("System.")) { interfaceType = i; break; } } pool.AddService(interfaceType, service); } }
public async void Initialize(IServicePool servicePool) { _sessionService = servicePool.GetService <ISessionService>(); this.AddCommand = new DelegateCommand(p => true, this.ExecuteAddCommand); this.DeleteCommand = new DelegateCommand(p => true, this.ExecuteDeleteCommand); this.CancelDeleteCommand = new DelegateCommand(p => true, this.ExecuteCancelDeleteCommand); this.IsBusy = true; _sessionList = await _sessionService.GetSessionListAsync(); _sessionList.Insert(0, new SessionDto { Title = "" }); this.SessionsView = new ListCollectionView(_sessionList); this.Slots = await _sessionService.AllSlotsAsync(); this.SlotsView = new ListCollectionView(this.Slots); foreach (var item in this.Slots) { item.PropertyChanged += this.OnScheduleItemPropertyChanged; } this.IsBusy = false; this.ErrorText = "Mindestens eine Session wurde mehrfach zugewiesen!"; }
public void DiscoverServices(IServicePool pool) { var registration = new RegistrationBuilder(); registration.ForTypesDerivedFrom <IService>().SelectConstructor((ConstructorInfo[] cInfo) => { if (cInfo.Length == 0) { return(null); } return(cInfo[0]); }).Export <IService>(); var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var catalog = new DirectoryCatalog(path, registration); var container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); var services = container.GetExportedValues <IService>(); foreach (var service in services) { service.ServicePool = pool; var interfaces = service.GetType().GetInterfaces(); Type interfaceType = null; foreach (var i in interfaces) { var name = i.FullName; if (!name.Contains("Contracts.IService") && !name.Contains("System.")) { interfaceType = i; break; } } pool.AddService(interfaceType, service); } }
public static T GetSingelService <T>(this IServicePool source, string descriptor) where T : class, IService { return(source.GetServiceInternal() .Where( m => m.Metadata.Contracts.Any(f => f == typeof(T)) && m.Metadata.Descriptor == descriptor) .Select(m => m.Value as T).FirstOrDefault()); }
/// <summary> /// Releases item from pool's locked item list /// </summary> public void ReleasePoolItem <TService>(TService service) { BuiltServiceDescriptor descriptor = _services[typeof(TService)]; IServicePool pool = (IServicePool)descriptor.Instance; pool.ReleaseInstance(service); }
public static IEnumerable <T> GetServices <T>(this IServicePool source, string descriptor) where T : class, IService { return(source.GetServiceInternal() .Where( m => m.Metadata.Contracts.Any(f => f == typeof(T)) && m.Metadata.Descriptor == descriptor) .Select(s => s.Value as T)); }
/// <summary> /// Releases item from pool's locked item list /// </summary> public void ReleasePoolItem <TService>(TService service) { ServiceDescriptor descriptor = GetDescriptor <TService>(); IServicePool pool = (IServicePool)descriptor.Instance; pool.ReleaseInstance(service); }
internal ApplicationContext(IImportPool importPool, IMessageBroker messageBroker, IServicePool servicePool, IDataBroker dataBroker, IVisualModuleManager visualModuleManager) { VisualModuleManager = visualModuleManager; DataBroker = dataBroker; ServicePool = servicePool; MessageBroker = messageBroker; ImportPool = importPool; }
public static T GetSingelService <T>(this IServicePool source, [Required] IServiceMetadata metadata) where T : class, IService { return(source.GetFirstOrDefault <T>( m => m.Metadata.Contracts == metadata.Contracts && m.Metadata.Descriptor == metadata.Descriptor && m.Metadata.ToString() == metadata.ToString())); }
public ApplicationContext(IImportPool importPool, IMessageBroker messageBroker, IServicePool servicePool, IDataBroker dataBroker, IVisualModuleManager visualModuleManager) { VisualModuleManager = visualModuleManager; DataBroker = dataBroker; ServicePool = servicePool; MessageBroker = messageBroker; ImportPool = importPool; }
public static T GetSingelService <T>(this IServicePool source, [Required] IServiceMetadata metadata) where T : class, IService { return(source.GetServiceInternal() .Where( m => m.Metadata.Contracts == metadata.Contracts && m.Metadata.Descriptor == metadata.Descriptor && m.Metadata.ToString() == metadata.ToString()) .Select(m => m.Value as T).FirstOrDefault()); }
public static IEnumerable <T> GetServices <T>(this IServicePool source, [Required] IServiceMetadata metadata) where T : class, IService { return(source.GetServiceInternal() .Where(m => m.Metadata.Contracts == metadata.Contracts && m.Metadata.Descriptor == metadata.Descriptor && m.Metadata.IsDefauldService == metadata.IsDefauldService && m.Metadata.ToString() == metadata.ToString()) .Select(s => s.Value as T)); }
public static T GetFirstOrDefault <T>(this IServicePool source, Func <Lazy <IService, IServiceMetadata>, bool> selector) where T : class, IService { var firstOrDefault = source.GetServiceInternal().FirstOrDefault(selector); if (firstOrDefault != null) { return(firstOrDefault.Value as T); } return(null); }
public static bool TryGetSingelMetadata(this IServicePool source, [Out] IServiceMetadata output) { output = default(IServiceMetadata); try { output = source.GetServiceInternal().Select(s => s.Metadata).FirstOrDefault(); return(true); } catch (Exception) { return(false); } }
public async void Initialize(IServicePool servicePool) { _sessionService = servicePool.GetService <ISessionService>(); this.AddCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteAddCommand); this.EditCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteEditCommand); this.OkCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteOkCommand); this.CancelEditCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteCancelEditCommand); this.DeleteCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteDeleteCommand); this.CancelDeleteCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteCancelDeleteCommand); this.IsBusy = true; _speakerList = await _sessionService.GetSpeakerListAsync(); _speakerList.Insert(0, new Speaker { Id = 0, Name = " " }); this.SpeakersView = new ListCollectionView(_speakerList); var trackList = await _sessionService.GetTrackListAsync(); _uiTrackList = new List <UITrack>(); foreach (var track in trackList) { var uiTrack = new UITrack(track); _uiTrackList.Add(uiTrack); uiTrack.PropertyChanged += this.OnUITrackPropertyChanged; } this.TracksView = new ListCollectionView(_uiTrackList); var sessionTypeList = await _sessionService.GetSessionTypesAsync(); this.SessionTypesView = new ListCollectionView(sessionTypeList); this.Sessions = await _sessionService.GetSessionListAsync(); this.SessionsView = new ListCollectionView(this.Sessions); this.SessionsView.CurrentChanged += this.OnCurrentSessionChanged; this.SessionsView.CurrentChanging += this.OnCurrentSessionChanging; _editView = this.SessionsView as IEditableCollectionViewAddNewItem; if (this.SessionsView.CurrentItem != null) { this.SetCurrentSession(this.SessionsView.CurrentItem as SessionDto); } this.IsBusy = false; }
public static bool TryGetServices <T>(this IServicePool source, [Out][Required] IEnumerable <T> output, IServiceMetadata metadata) where T : class, IService { output = default(IEnumerable <T>); try { output = source.GetServiceInternal() .Where(m => m.Metadata == metadata) .Select(m => m.Value as T); return(true); } catch (Exception) { return(false); } }
public static bool TryGetSingelService <T>(this IServicePool source, [Out][Required] T output, IServiceMetadata metadata) where T : class { output = default(T); try { output = source.GetServiceInternal() .Where(m => m.Metadata == metadata) .Select(m => m.Value as T).FirstOrDefault(); return(true); } catch (Exception) { return(false); } }
public static bool TryGetServices <T>(this IServicePool source, [Out][Required] IEnumerable <T> output, string descriptor) where T : class, IService { output = default(IEnumerable <T>); try { output = source.GetServiceInternal() .Where( m => m.Metadata.Contracts.Any(f => f == typeof(T)) && m.Metadata.Descriptor == descriptor) .Select(m => m.Value as T); return(true); } catch (Exception) { return(false); } }
public async void Initialize(IServicePool servicePool) { _sessionService = servicePool.GetService<ISessionService>(); _sessionService.RatingUpdated += this.OnRatingUpdated; this.AddCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteAddCommand); this.DeleteCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteDeleteCommand); this.CancelDeleteCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteCancelDeleteCommand); this.IsBusy = true; this.Ratings = await _sessionService.GetRatingListAsync(); this.RatingsView = new ListCollectionView(this.Ratings); var sessions = await _sessionService.GetSessionListAsync(); this.SessionsView = new ListCollectionView(sessions); this.SessionsView.CurrentChanged += this.OnCurrentSessionChanged; this.OnCurrentSessionChanged(null, EventArgs.Empty); this.IsBusy = false; }
/// <summary> /// Adds a pool instance to using list /// This instance will be released while disposing /// </summary> public void UsePoolItem(IServicePool pool, PoolServiceDescriptor descriptor) { lock (_poolInstances) { if (_poolInstances.ContainsKey(pool)) { if (pool.Type == ImplementationType.Transient) { _poolInstances[pool].Add(descriptor); } } else { _poolInstances.Add(pool, new List <PoolServiceDescriptor> { descriptor }); } } }
public async void Initialize(IServicePool servicePool) { _sessionService = servicePool.GetService<ISessionService>(); this.AddCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteAddCommand); this.EditCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteEditCommand); this.OkCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteOkCommand); this.CancelEditCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteCancelEditCommand); this.DeleteCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteDeleteCommand); this.CancelDeleteCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteCancelDeleteCommand); this.IsBusy = true; this.Speakers = await _sessionService.GetSpeakerListAsync(); this.SpeakersView = new ListCollectionView(this.Speakers); this.SpeakersView.CurrentChanging += this.OnCurrentSpeakerChanging; this.SpeakersView.CurrentChanged += this.OnCurrentSpeakerChanged; _editView = this.SpeakersView as IEditableCollectionViewAddNewItem; this.OnCurrentSpeakerChanged(null, EventArgs.Empty); this.IsBusy = false; }
public async void Initialize(IServicePool servicePool) { _sessionService = servicePool.GetService <ISessionService>(); _sessionService.RatingUpdated += this.OnRatingUpdated; this.AddCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteAddCommand); this.DeleteCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteDeleteCommand); this.CancelDeleteCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteCancelDeleteCommand); this.IsBusy = true; this.Ratings = await _sessionService.GetRatingListAsync(); this.RatingsView = new ListCollectionView(this.Ratings); var sessions = await _sessionService.GetSessionListAsync(); this.SessionsView = new ListCollectionView(sessions); this.SessionsView.CurrentChanged += this.OnCurrentSessionChanged; this.OnCurrentSessionChanged(null, EventArgs.Empty); this.IsBusy = false; }
public static bool TryGetSingelService <T>(this IServicePool source, [Out][Required] T output, string descriptor) where T : class { //Requires.NotNull<ICompositionService>(compositionService, "compositionService"); //Requires.NotNull<object>(attributedPart, "attributedPart"); output = default(T); try { output = source.GetServiceInternal() .Where( m => m.Metadata.Contracts.Any(f => f == typeof(T)) && m.Metadata.Descriptor == descriptor) .Select(m => m.Value as T).FirstOrDefault(); return(true); } catch (Exception) { return(false); } }
public async void Initialize(IServicePool servicePool) { _sessionService = servicePool.GetService<ISessionService>(); this.AddCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteAddCommand); this.EditCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteEditCommand); this.OkCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteOkCommand); this.CancelEditCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteCancelEditCommand); this.DeleteCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteDeleteCommand); this.CancelDeleteCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteCancelDeleteCommand); this.IsBusy = true; _speakerList = await _sessionService.GetSpeakerListAsync(); _speakerList.Insert(0, new Speaker { Id = 0, Name = " " }); this.SpeakersView = new ListCollectionView(_speakerList); var trackList = await _sessionService.GetTrackListAsync(); _uiTrackList = new List<UITrack>(); foreach (var track in trackList) { var uiTrack = new UITrack(track); _uiTrackList.Add(uiTrack); uiTrack.PropertyChanged += this.OnUITrackPropertyChanged; } this.TracksView = new ListCollectionView(_uiTrackList); var sessionTypeList = await _sessionService.GetSessionTypesAsync(); this.SessionTypesView = new ListCollectionView(sessionTypeList); this.Sessions = await _sessionService.GetSessionListAsync(); this.SessionsView = new ListCollectionView(this.Sessions); this.SessionsView.CurrentChanged += this.OnCurrentSessionChanged; this.SessionsView.CurrentChanging += this.OnCurrentSessionChanging; _editView = this.SessionsView as IEditableCollectionViewAddNewItem; if (this.SessionsView.CurrentItem != null) this.SetCurrentSession(this.SessionsView.CurrentItem as SessionDto); this.IsBusy = false; }
private object GetFromPool(BuiltServiceDescriptor descriptor, IContainerScope scope) { IServicePool pool = (IServicePool)descriptor.Instance; PoolServiceDescriptor pdesc = pool.GetAndLock(scope); if (pdesc == null) { throw new NullReferenceException($"{descriptor.ServiceType.ToTypeString()} Service is not registered in the container"); } if (pool.Type == ImplementationType.Scoped && scope == null) { throw new ScopeException($"{descriptor.ServiceType.ToTypeString()} is registered as Scoped but scope parameter is null for IServiceContainer.Get method"); } if (scope != null) { scope.UsePoolItem(pool, pdesc); } return(pdesc.GetInstance()); }
public async void Initialize(IServicePool servicePool) { _sessionService = servicePool.GetService <ISessionService>(); this.AddCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteAddCommand); this.EditCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteEditCommand); this.OkCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteOkCommand); this.CancelEditCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteCancelEditCommand); this.DeleteCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteDeleteCommand); this.CancelDeleteCommand = new DelegateCommand(p => !this.IsBusy, this.ExecuteCancelDeleteCommand); this.IsBusy = true; this.Speakers = await _sessionService.GetSpeakerListAsync(); this.SpeakersView = new ListCollectionView(this.Speakers); this.SpeakersView.CurrentChanging += this.OnCurrentSpeakerChanging; this.SpeakersView.CurrentChanged += this.OnCurrentSpeakerChanged; _editView = this.SpeakersView as IEditableCollectionViewAddNewItem; this.OnCurrentSpeakerChanged(null, EventArgs.Empty); this.IsBusy = false; }
public async void Initialize(IServicePool servicePool) { _sessionService = servicePool.GetService<ISessionService>(); this.AddCommand = new DelegateCommand(p => true, this.ExecuteAddCommand); this.DeleteCommand = new DelegateCommand(p => true, this.ExecuteDeleteCommand); this.CancelDeleteCommand = new DelegateCommand(p => true, this.ExecuteCancelDeleteCommand); this.IsBusy = true; _sessionList = await _sessionService.GetSessionListAsync(); _sessionList.Insert(0, new SessionDto { Title = "" }); this.SessionsView = new ListCollectionView(_sessionList); this.Slots = await _sessionService.AllSlotsAsync(); this.SlotsView = new ListCollectionView(this.Slots); foreach (var item in this.Slots) { item.PropertyChanged += this.OnScheduleItemPropertyChanged; } this.IsBusy = false; this.ErrorText = "Mindestens eine Session wurde mehrfach zugewiesen!"; }
public static T GetSingelService <T>(this IServicePool source, string descriptor) where T : class, IService { return (source.GetFirstOrDefault <T>( m => m.Metadata.Contracts.Any(f => f == typeof(T)) && m.Metadata.Descriptor == descriptor)); }
private async Task <object> Get(ServiceDescriptor descriptor, IContainerScope scope = null) { if (descriptor.IsPool) { IServicePool pool = (IServicePool)descriptor.Instance; PoolServiceDescriptor pdesc = await pool.GetAndLock(scope); if (pdesc == null) { throw new NullReferenceException("Could not get service from container"); } if (pool.Type == ImplementationType.Scoped && scope == null) { throw new InvalidOperationException("Type is registered as Scoped but scope parameter is null for IServiceContainer.Get method"); } if (scope != null) { scope.UsePoolItem(pool, pdesc); } return(pdesc.GetInstance()); } switch (descriptor.Implementation) { //create new instance case ImplementationType.Transient: object transient = await CreateInstance(descriptor.ImplementationType, scope); if (descriptor.AfterCreatedMethod != null) { descriptor.AfterCreatedMethod.DynamicInvoke(transient); } if (descriptor.ProxyType != null) { IServiceProxy p = (IServiceProxy) await CreateInstance(descriptor.ProxyType, scope); return(p.Proxy(transient)); } return(transient); case ImplementationType.Scoped: if (scope == null) { throw new InvalidOperationException("Type is registered as Scoped but scope parameter is null for IServiceContainer.Get method"); } return(await scope.Get(descriptor, this)); case ImplementationType.Singleton: //if instance already created return if (descriptor.Instance != null) { return(descriptor.Instance); } //create instance for first time and set Instance property of descriptor to prevent re-create for next times object instance = await CreateInstance(descriptor.ImplementationType, scope); if (descriptor.AfterCreatedMethod != null) { descriptor.AfterCreatedMethod.DynamicInvoke(instance); } if (descriptor.ProxyType != null) { IServiceProxy p = (IServiceProxy) await CreateInstance(descriptor.ProxyType, scope); object proxyObject = p.Proxy(instance); descriptor.Instance = proxyObject; } else { descriptor.Instance = instance; } return(descriptor.Instance); default: return(null); } }
public ServiceProxy(IServicePool servicePool, IEnumerable <CallInterceptor> interceptors) { _servicePool = servicePool; _interceptors = interceptors; }
public async void Initialize(IServicePool pool) { _isInititializing = true; this.State = "ReadOnly"; if (Application.Current != null && Application.Current.MainWindow != null && !DesignerProperties.GetIsInDesignMode(Application.Current.MainWindow)) { _speakerService = pool.GetService<ISpeakersService>(); this.SaveCommand = new DelegateCommand(this.CanExecuteSaveCommand, this.ExecuteSaveCommand); var list = await _speakerService.GetSpeakerListAsync(); this.SpeakerList = new ObservableCollection<SpeakerDto>(list); this.CurrentSpeaker = this.SpeakerList[0]; this.SpeakerListView = new ListCollectionView(this.SpeakerList); this.SpeakerListView.CurrentChanged += SpeakerListView_CurrentChanged; this.SpeakerListView.MoveCurrentTo(this.SpeakerList[1]); //this.SpeakerListView.Filter = item => ((Speaker)item).FirstName.StartsWith("C"); _speakerEditView = this.SpeakerListView as IEditableCollectionView; } _isInititializing = false; }
private static T GetSingelDefauldService <T>(this IServicePool source) where T : class, IService { return(source.GetFirstOrDefault <T>(m => m.Metadata.Contracts.Any(f => f == typeof(T)))); }
public static IServiceMetadata GetSingelMetadata(this IServicePool source) { return(source.GetServiceInternal().Select(s => s.Metadata).FirstOrDefault()); }
private static T GetSingelDefauldService <T>(this IServicePool source) where T : class, IService { return(source.GetServiceInternal(false) .Where(m => m.Metadata.Contracts.Any(f => f == typeof(T))) .Select(m => m.Value as T).FirstOrDefault()); }