当前位置: 首页>>代码示例>>C#>>正文


C# IKernel.ReleaseComponent方法代码示例

本文整理汇总了C#中IKernel.ReleaseComponent方法的典型用法代码示例。如果您正苦于以下问题:C# IKernel.ReleaseComponent方法的具体用法?C# IKernel.ReleaseComponent怎么用?C# IKernel.ReleaseComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IKernel的用法示例。


在下文中一共展示了IKernel.ReleaseComponent方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ObtainInterceptors

		/// <summary>
		/// Obtains the interceptors associated with the component.
		/// </summary>
		/// <param name="kernel">The kernel instance</param>
		/// <param name="model">The component model</param>
		/// <param name="context">The creation context</param>
		/// <returns>interceptors array</returns>
		protected IInterceptor[] ObtainInterceptors(IKernel kernel, ComponentModel model, CreationContext context)
		{
			var interceptors = new List<IInterceptor>();
			foreach (IReference<IInterceptor> interceptorRef in GetInterceptorsFor(model))
			{
				try
				{
					var interceptor = interceptorRef.Resolve(kernel, context);
					SetOnBehalfAware(interceptor as IOnBehalfAware, model);
					interceptors.Add(interceptor);
				}
				catch (Exception e)
				{
					foreach (var interceptor in interceptors)
					{
						kernel.ReleaseComponent(interceptor);
					}

					if(e is InvalidCastException)
					{
						var message = String.Format(
						"An interceptor registered for {0} doesn't implement the {1} interface",
						model.Name, typeof(IInterceptor).Name);

						throw new DependencyResolverException(message);
					}
					throw;
				}
			}

			return interceptors.ToArray();
		}
开发者ID:pmcg,项目名称:Castle.Windsor,代码行数:39,代码来源:AbstractProxyFactory.cs

示例2: OnCreateTaskWizardViewModel

 private void OnCreateTaskWizardViewModel(IKernel k, TaskWizardViewModel o)
 {
     o.Closed += (s, e) =>
     {
         k.ReleaseComponent(o);
     };
 }
开发者ID:Jedzia,项目名称:BackBock,代码行数:7,代码来源:ViewModelInstaller.cs

示例3: ReleaseHook

		private void ReleaseHook(ProxyGenerationOptions proxyGenOptions, IKernel kernel)
		{
			if (proxyGenOptions.Hook == null)
			{
				return;
			}
			kernel.ReleaseComponent(proxyGenOptions.Hook);
		}
开发者ID:aledeniz,项目名称:Castle.Windsor,代码行数:8,代码来源:DefaultProxyFactory.cs

示例4: CreateCloudQueueClient

        private static CloudQueueClient CreateCloudQueueClient(IKernel kernel)
        {
            var storageAccount = kernel.Resolve<CloudStorageAccount>();
            CloudQueueClient client = storageAccount.CreateCloudQueueClient();
            kernel.ReleaseComponent(storageAccount);

            return client;
        }
开发者ID:rustyrazorblade,项目名称:killrvideo-csharp,代码行数:8,代码来源:UploadsWorkerWindsorInstaller.cs

示例5: CreateCloudStorageAccount

        private static CloudStorageAccount CreateCloudStorageAccount(IKernel kernel)
        {
            // Get Azure configurations
            var configRetriever = kernel.Resolve<IGetEnvironmentConfiguration>();
            string storageConnectionString = configRetriever.GetSetting(StorageConnectionStringAppSettingsKey);
            kernel.ReleaseComponent(configRetriever);

            return CloudStorageAccount.Parse(storageConnectionString);
        }
开发者ID:rustyrazorblade,项目名称:killrvideo-csharp,代码行数:9,代码来源:UploadsWorkerWindsorInstaller.cs

示例6: CreateLeaseManagerConfig

        private static LeaseManagerConfig CreateLeaseManagerConfig(IKernel kernel)
        {
            // Configure the lease manager
            var configRetriever = kernel.Resolve<IGetEnvironmentConfiguration>();
            var leaseManagerConfig = new LeaseManagerConfig { LeaseName = "SampleDataJobs", UniqueId = configRetriever.UniqueInstanceId };
            kernel.ReleaseComponent(configRetriever);

            return leaseManagerConfig;
        }
开发者ID:rustyrazorblade,项目名称:killrvideo-csharp,代码行数:9,代码来源:SampleDataWorkerWindsorInstaller.cs

示例7: CreateCredentials

        private static MediaServicesCredentials CreateCredentials(IKernel kernel)
        {
            // Get Azure configurations
            var configRetriever = kernel.Resolve<IGetEnvironmentConfiguration>();
            string mediaServicesAccountName = configRetriever.GetSetting(MediaServicesNameAppSettingsKey);
            string mediaServicesAccountKey = configRetriever.GetSetting(MediaServicesKeyAppSettingsKey);
            kernel.ReleaseComponent(configRetriever);

            // Return the credentials
            return new MediaServicesCredentials(mediaServicesAccountName, mediaServicesAccountKey);
        }
开发者ID:rustyrazorblade,项目名称:killrvideo-csharp,代码行数:11,代码来源:UploadsWorkerWindsorInstaller.cs

示例8: CreateSession

 private static ISession CreateSession(IKernel kernel)
 {
     var sessionFactory = kernel.Resolve<ISessionFactory>();
     try
     {
         return sessionFactory.OpenSession();
     }
     finally
     {
         kernel.ReleaseComponent(sessionFactory);
     }
 }
开发者ID:gimmi,项目名称:randomhacking,代码行数:12,代码来源:Global.asax.cs

示例9: CreateYouTubeService

        private static YouTubeService CreateYouTubeService(IKernel kernel)
        {
            var configRetriever = kernel.Resolve<IGetEnvironmentConfiguration>();
            string apiKey = configRetriever.GetSetting(YouTubeApiKey);
            kernel.ReleaseComponent(configRetriever);

            // Create client for YouTube API
            var youTubeInit = new BaseClientService.Initializer
            {
                ApiKey = apiKey,
                ApplicationName = "KillrVideo.SampleData.Worker"
            };
            return new YouTubeService(youTubeInit);
        }
开发者ID:rustyrazorblade,项目名称:killrvideo-csharp,代码行数:14,代码来源:SampleDataWorkerWindsorInstaller.cs

示例10: CreateCassandraSession

        private static ISession CreateCassandraSession(IKernel kernel)
        {
            // Get cluster IP/host and keyspace from .config file
            var configRetriever = kernel.Resolve<IGetEnvironmentConfiguration>();
            string clusterLocation = configRetriever.GetSetting(ClusterLocationAppSettingsKey);
            kernel.ReleaseComponent(configRetriever);

            // Start a cluster builder for connecting to Cassandra
            Builder builder = Cluster.Builder();

            // Allow multiple comma delimited locations to be specified in the configuration
            string[] locations = clusterLocation.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(l => l.Trim()).ToArray();
            foreach (string location in locations)
            {
                string[] hostAndPort = location.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                if (hostAndPort.Length == 1)
                {
                    // Just an IP address or host name
                    builder = builder.AddContactPoint(hostAndPort[0]);
                }
                else if (hostAndPort.Length == 2)
                {
                    // IP Address plus host name
                    var ipEndPoint = new IPEndPoint(IPAddress.Parse(hostAndPort[0]), int.Parse(hostAndPort[1]));
                    builder = builder.AddContactPoint(ipEndPoint);
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Unable to parse Cassandra cluster location '{0}' from configuration.", location));
                }
            }

            // Use the Cluster builder to create a cluster
            Cluster cluster = builder.Build();

            // Use the cluster to connect a session to the appropriate keyspace
            ISession session;
            try
            {
                session = cluster.Connect(Keyspace);
            }
            catch (Exception e)
            {
                Logger.Error(string.Format("Exception while connecting to keyspace '{0}' using hosts '{1}'", Keyspace, clusterLocation), e);
                throw;
            }

            return session;
        }
开发者ID:johnbabb,项目名称:killrvideo-csharp,代码行数:49,代码来源:CassandraWindsorInstaller.cs

示例11: SetUp

		public void SetUp()
		{
			kernel = new DefaultKernel();

			kernel.AddFacility<StartableFacility>();

			kernel.Register(
				Component.For<StartableDisposableAndInitializableComponent>()
					.LifeStyle.Transient
				);

			component = kernel.Resolve<StartableDisposableAndInitializableComponent>();
			component.DoSomething();
			kernel.ReleaseComponent(component);

			calledMethods = component.calledMethods;
		}
开发者ID:AGiorgetti,项目名称:Castle.InversionOfControl,代码行数:17,代码来源:IoC_113.cs

示例12: CreateNotificationEndPoint

        private static INotificationEndPoint CreateNotificationEndPoint(IKernel kernel)
        {
            var cloudMediaContext = kernel.Resolve<CloudMediaContext>();
            var cloudQueueClient = kernel.Resolve<CloudQueueClient>();

            try
            {
                // ReSharper disable once ReplaceWithSingleCallToFirstOrDefault
                INotificationEndPoint endpoint = cloudMediaContext.NotificationEndPoints
                                                                   .Where(ep => ep.Name == UploadConfig.NotificationQueueName)
                                                                   .FirstOrDefault();
                if (endpoint != null)
                    return endpoint;

                // Make sure the queue exists in Azure Storage
                var notificationQueue = cloudQueueClient.GetQueueReference(UploadConfig.NotificationQueueName);
                notificationQueue.CreateIfNotExists();

                // Create the endpoint
                return cloudMediaContext.NotificationEndPoints.Create(UploadConfig.NotificationQueueName, NotificationEndPointType.AzureQueue,
                                                                       UploadConfig.NotificationQueueName);
            }
            finally
            {
                kernel.ReleaseComponent(cloudMediaContext);
                kernel.ReleaseComponent(cloudQueueClient);
            }
        }
开发者ID:rustyrazorblade,项目名称:killrvideo-csharp,代码行数:28,代码来源:UploadsWorkerWindsorInstaller.cs

示例13: ObtainInterceptors

		/// <summary>
		/// Obtains the interceptors associated with the component.
		/// </summary>
		/// <param name="kernel">The kernel instance</param>
		/// <param name="model">The component model</param>
		/// <param name="context">The creation context</param>
		/// <returns>interceptors array</returns>
		protected IInterceptor[] ObtainInterceptors(IKernel kernel, ComponentModel model, CreationContext context)
		{
			var interceptors = new List<IInterceptor>();
			foreach (var interceptorRef in GetInterceptorsFor(model))
			{
				var handler = GetInterceptorHandler(interceptorRef, kernel);
				if (handler == null)
				{
					// This should be virtually impossible to happen
					// Seriously!
					throw new DependencyResolverException(string.Format("The interceptor {0} could not be resolved", interceptorRef));
				}

				if(handler.IsBeingResolvedInContext(context))
				{
					throw new DependencyResolverException(
						string.Format(
							"Cycle detected - interceptor {0} wants to use itself as its interceptor. This usually signifies a bug in custom {1}",
							handler.ComponentModel.Name, typeof(IModelInterceptorsSelector).Name));
				}

				try
				{
					var contextForInterceptor = RebuildContext(handler.Service, context);
					var interceptor = (IInterceptor)handler.Resolve(contextForInterceptor);

					interceptors.Add(interceptor);

					SetOnBehalfAware(interceptor as IOnBehalfAware, model);
				}
				catch (Exception e)
				{
					foreach (var interceptor in interceptors)
					{
						kernel.ReleaseComponent(interceptor);
					}

					if(e is InvalidCastException)
					{
						var message = String.Format(
						"An interceptor registered for {0} doesn't implement the {1} interface",
						model.Name, typeof(IInterceptor).Name);

						throw new DependencyResolverException(message);
					}
					throw;
				}
			}

			return interceptors.ToArray();
		}
开发者ID:vbedegi,项目名称:Castle.InversionOfControl,代码行数:58,代码来源:AbstractProxyFactory.cs


注:本文中的IKernel.ReleaseComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。