예제 #1
0
        public virtual bool IsSupported <T>() where T : class
        {
            try
            {
                var context = new ServiceNodeServiceProviderContext(this);
                foreach (IServiceNodeServiceProvider provider in new ServiceNodeServiceProviderExtensionPoint().CreateExtensions())
                {
                    provider.SetContext(context);
                    if (provider.IsSupported(typeof(T)))
                    {
                        return(true);
                    }
                }
            }
            catch (NotSupportedException)
            {
            }

            return(false);
        }
예제 #2
0
        public virtual T GetService <T>() where T : class
        {
            try
            {
                var context = new ServiceNodeServiceProviderContext(this);
                foreach (IServiceNodeServiceProvider provider in new ServiceNodeServiceProviderExtensionPoint().CreateExtensions())
                {
                    provider.SetContext(context);
                    var service = provider.GetService(typeof(T));
                    if (service != null)
                    {
                        return(service as T);
                    }
                }
            }
            catch (NotSupportedException)
            {
            }

            throw new NotSupportedException(String.Format("Service node doesn't support service '{0}'.", typeof(T).FullName));
        }