本文整理汇总了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();
}
示例2: OnCreateTaskWizardViewModel
private void OnCreateTaskWizardViewModel(IKernel k, TaskWizardViewModel o)
{
o.Closed += (s, e) =>
{
k.ReleaseComponent(o);
};
}
示例3: ReleaseHook
private void ReleaseHook(ProxyGenerationOptions proxyGenOptions, IKernel kernel)
{
if (proxyGenOptions.Hook == null)
{
return;
}
kernel.ReleaseComponent(proxyGenOptions.Hook);
}
示例4: CreateCloudQueueClient
private static CloudQueueClient CreateCloudQueueClient(IKernel kernel)
{
var storageAccount = kernel.Resolve<CloudStorageAccount>();
CloudQueueClient client = storageAccount.CreateCloudQueueClient();
kernel.ReleaseComponent(storageAccount);
return client;
}
示例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);
}
示例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;
}
示例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);
}
示例8: CreateSession
private static ISession CreateSession(IKernel kernel)
{
var sessionFactory = kernel.Resolve<ISessionFactory>();
try
{
return sessionFactory.OpenSession();
}
finally
{
kernel.ReleaseComponent(sessionFactory);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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();
}