コード例 #1
0
        public async Task Initialize()
        {
            IComponentModel componentModel = await asyncServiceProvider.GetServiceAsync(typeof(SComponentModel)) as IComponentModel;

            Log.Assert(componentModel != null, "Service of type SComponentModel not found");
            if (componentModel == null)
            {
                log.Error("Service of type SComponentModel not found");
                return;
            }

            ExportProvider = componentModel.DefaultExportProvider;
            if (ExportProvider == null)
            {
                log.Error("DefaultExportProvider could not be obtained");
            }
            initialized = true;
        }
コード例 #2
0
        /// <summary>
        /// Removes a service from the catalog
        /// </summary>
        /// <param name="t">The type we want to remove</param>
        /// <param name="owner">The owner, which either has to match what was passed to AddService,
        /// or if it's null, the service will be removed without checking for ownership</param>
        public void RemoveService(Type t, object owner)
        {
            Guard.ArgumentNotNull(t, nameof(t));

            string contract = AttributedModelServices.GetContractName(t);

            Log.Assert(!string.IsNullOrEmpty(contract), "Every type must have a contract name");

            OwnedComposablePart part;

            if (tempParts.TryGetValue(contract, out part))
            {
                if (owner != null && part.Owner != owner)
                {
                    return;
                }
                tempParts.Remove(contract);
                var batch = new CompositionBatch();
                batch.RemovePart(part.Part);
                TempContainer.Compose(batch);
            }
        }